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
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.
also this can happen if your activiti in mannifest has next launchMode:
<activity android:name=".SecondActivity"
...
android:launchMode="singleInstance"
android:parentActivityName=".MainActiviy"
...
/>
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).
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!
You should add this to the MainActivity on the AndroidManifest:
<activity
android:name=".MainActivity"
android:allowTaskReparenting="true" />