lundi 11 mai 2015

Launching Activity from Notification put 2 Activities in the stack

I am having a problem when the user launched my app by pressing A notification action.

I can reproduce it by doing the following.

user launches the app then presses the home button so that the MainActivity is still in the stack.

Now a notification comes in and the user presses on it, that notification launches MainActivity again.

When you hit the back button to exit the app you see the original instance of MainActivity again.

this is how I have my notification flags

Intent i = new Intent(context,MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
nBuilder.addAction(R.drawable.ic_forward_white_24dp,"Open Message",PendingIntent.getActivity(context,4,i,PendingIntent.FLAG_UPDATE_CURRENT));

I cannot use singleTask in my manifest because I need to use startActivityForResult

I even tried using FLAG_ACTIVITY_REORDER_TO_FRONT to try to just use onNewIntent of the activity but that didn't work either

How can I remove the first instance of MainActivity so they it is not in the stack twice when you hit the back button after a notification?

Aucun commentaire:

Enregistrer un commentaire