I have a main activity which is marked as singleInstance
. I then have a notification which opens a different activity, below are both declarations:
<activity android:name="MainActivity" android:launchMode="singleInstance".....
<activity android:name="some.long.package.from.a.library.NotificationActivity" android:noHistory="true" android:launchMode="singleInstance" android:parentActivityName=".MainActivity">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity"/>
</activity>
When I create the notification I modify the task stack so it inserts the parent activity:
Intent intent = new Intent(context, NotificationActivity.class);
PendingIntent pendingIntent = TaskStackBuilder.create(context)
.addNextIntentWithParentStack(intent)
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
This all works great except for one little issue, when I touch the notification and go to the NotificationActivity
and then use the back button or the back on the action bar, it goes to a whole new instance of MainActivity
.
I know singleInstance
isn't the ideal launch mode to use in most situations, however I have an application which is sort of like a web browser and ideally the user should get back exactly to where in the browser they were. I could save the page address and reload it (which I will for worst case scenario) but imagine if you were in the middle of filling out a long form and your browser did that just because you acknowledged a notification.
So can anyone tell me why singleInstance
is being ignored after I modify the task stack on a pending intent?
Thanks.