I start activity from notification with pending intent with back stack. Here is how I make it
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
stackBuilder.addNextIntentWithParentStack(intent);
stackBuilder.editIntentAt(0).putExtra(GCMUtils.NEXT_INTENT,BaseFragment.FragmentId.DIALOGS).
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
resultPendingIntent = stackBuilder.getPendingIntent(requestCode, PendingIntent.FLAG_ONE_SHOT);
Then from activity A(started with intent
) I start activity B and finish activity A
Bundle extras = activity.getIntent().getExtras();
boolean isFromNotification = extras != null &&
extras.getBoolean(GCMUtils.NOTIFICATION_INTENT, false);
boolean noBackStack = isFromNotification &&
Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB;
if (activity.isTaskRoot() || noBackStack) {
Intent intent = activity instanceof ActionBarActivity ?
((ActionBarActivity)activity).getSupportParentActivityIntent() :
NavUtils.getParentActivityIntent(activity);
if (noBackStack) {
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
}
activity.startActivity(intent);
activity.finish();
} else {
activity.onBackPressed();
}
After that I exit my app with back button (activity B is main activity). Now if open recent apps and click my app it will restore activity A instead of activity B. It reproduces on android 2.3. I don't understand why it restores A instead of B. What am I missing?