Resume application and stack from notification

后端 未结 8 1669
一向
一向 2020-11-22 16:04

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 th

8条回答
  •  星月不相逢
    2020-11-22 16:47

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

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

    As the Intent you created to open your Activity from the 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.

提交回复
热议问题