Android - Build a notification, TaskStackBuilder.addParentStack not working

前端 未结 11 2579
说谎
说谎 2020-11-28 06:23

I\'m trying to launch an activity from a notification like the Android docs explain, but when I open the notification and then press the back button, the HomeActivity (paren

相关标签:
11条回答
  • 2020-11-28 06:44

    Have you looked in the Android documentation, specifically the Notifications API guide. It describes how to do this in detail.

    Notice that if the Activity you start from the notification is not part of the normal Activity flow, then it should not go to the start page of the app; instead, it should go to the Home screen.

    0 讨论(0)
  • 2020-11-28 06:45

    also this can happen if your activiti in mannifest has next launchMode:

    <activity android:name=".SecondActivity"
         ...
             android:launchMode="singleInstance"
             android:parentActivityName=".MainActiviy"
        ...
    />
    
    0 讨论(0)
  • 2020-11-28 06:46

    As stated in other answers, TaskStackBuilder doesn't work for versions below Honeycomb.

    My solution was to override the activity's onBackPressed() method.

    @Override
    public void onBackPressed() {
        NavUtils.navigateUpFromSameTask(this);
    }
    

    Obviously if you're planning on finishing the activity in some other manner you will have to handle that as well. (Though I imagine overriding finish() will have some unexpected behaviour).

    0 讨论(0)
  • 2020-11-28 06:47

    If none of the solutions are working and you are sure that you have followed everything carefully...then you need you uninstall the app and reinstall it. Worked for me!

    0 讨论(0)
  • 2020-11-28 06:52

    You should add this to the MainActivity on the AndroidManifest:

    <activity
       android:name=".MainActivity"
       android:allowTaskReparenting="true" />
    
    0 讨论(0)
提交回复
热议问题