Android PendingIntent. Back button closes the app instead of restoring the previous Activity from the stack

Viewed 1457

When I open an Activity from notification it seems like the current activity stack is cleared. Because when I press back button, the app closes (should return to the previous Activity).

I use following PendingIntent:

PendingIntent.getActivity(context, 0, new Intent(this, DetailsActivity.class, 0);

as a Content Intent of my notification. DetailsActivity is declared as "singleTop".

The ideal situation would be to have DetailsActivity opened on top of the stack only when there isn't there already. Which seems to be exactly what "singleTop" should do.

My AndroidManifest looks like this:

<activity
    android:name=".DetailsActivity"
    android:label="@string/app_name"
    android:theme="@style/Holo.Theme.Light"
    android:launchMode="singleTop">
</activity>
<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@style/Holo.Theme.Light" />

I use NotificationCompat.Builder to build notification. The Intent is just like in my question. The situation is exactly the same when I use:

Intent intent = new Intent(context, DetailsActivity.class);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(DetailsActivity.class);
stackBuilder.addNextIntent(intent);

PendingIntent pi = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

and:

<activity
    android:name=".DetailsActivity"
    android:label="@string/app_name"
    android:theme="@style/Holo.Theme.Light"
    android:parentActivityName=".MainActivity">
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".MainActivity" />
</activity>

The project uses HoloEverywhere library. I also don't override onBackPressed()

Why the application closes instead of restoring the previous activity?

0 Answers
Related