Resume application and stack from notification

后端 未结 8 1519
一向
一向 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 17:10

    I also had the same problem and try to resolve the problem like @GrAnd's answer:

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

    This works, no doubts about it but the problem is when you set your intent as ACTION_MAIN. Then you will not be able to set any bundle to the intent. I mean, your primitive data will not be received from the target activity because ACTION_MAIN can not contain any extra data.

    Instead of this, you can just set your activities as singleTask and call your intent normally without setting ACTION_MAIN and receive the intent from onNewIntent() method of your target activity.

    But beaware if you call, super.onNewIntent(intent); then a second instance of the activity will be created.

提交回复
热议问题