恢复应用程序,并从通知栈并从、应用程序、通知

2023-09-11 12:27:46 作者:戴耳钉的柔情少年-

我想因为当用户点击启动器的图标,以恢复在完全相同的方式从一个状态栏,通知我的应用程序。

I want to resume my app from a status bar notification in the exact same manner as when the user taps its icon in the launcher.

即:我想堆栈是在相同的状态,因为它是用户离开它之前

That is: I want the stack to be in the same state as it was before the user left it.

设定在通知一未决意图时的问题是,它总是针对特定活性。我不想这样。我只需要为发射做恢复应用程序。

The problem when setting a pending intent on the notification is that it always targets a specific activity. I don't want this. I need to resume the application just as the launcher does.

因此​​,如果用户在活动A,我要恢复活动A.如果他已经从一个活动启动的活动B,那么我想,当用户点击该通知B至显示,堆栈要这样恢复当用户点击后退按钮B中的一个被恢复。

So if the user is in activity A, I want to resume activity A. If he has launched activity B from activity A, then I want B to be displayed when the user taps the notification, and the stack to be restored so that A gets resumed when the user taps the back button in B.

有几个具有类似的标题问题的其他问题,但没有解决我的问题。

There are couple of other questions of questions with similar titles, but none address my problem.

推荐答案

只要使用相同的意图过滤器的Andr​​oid使用时,启动应用程序:

Just use the same intent filters as android uses when launches the app:

final Intent notificationIntent = new Intent(context, YourActivity.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

当你创建从通知栏打开活动的目的是一样的用于启动你的应用程序的Andr​​oid,在previously开业活动将显示,而不是创建一个新的来。

As the intent you created to open your activity from notification bar is the same as android used for launching your app, the previously opened activity will be shown instead of creating a new one.

 
精彩推荐