PendingIntent not recreating activity (with Extras) when it is already on history stack top

1.1k Views Asked by At

I am trying to start an Activity A from a Notification Button (using PendingIntent). When I tap on this Notification Button and A is on top of history stack, it just not behave correctly:

What it should do:

  • Activity A must duplicated on historystack, this way:
    1. When activity A is on top of history stack
      Before:
      [ A, ... old activities ... ]
      After:
      [ A, A, ... old activities ... ]
    2. When activity A is not on top of history stack (default behavior)
      Before:
      [ B, ... old activities ... ]
      After:
      [ A, B, ... old activities ... ]

What happens:

  1. onCreate is called, but getIntent().getExtras() is null.
  2. Activity A is replaced and not recreated (I want a duplicate).

I've tried a lot of things: Intent.FLAG* and PendingIntent.FLAG* also, but unsuccessfully.

Edit 1: I tried these constants:

  • Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
  • Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP (but I don't want to clear top)

Code (part):

Intent intentCancel = new Intent(getApplicationContext(), ChallengeProposalActivity.class);
//intent.setAction(String.valueOf(System.currentTimeMillis()));
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(ChallengeProposal.NAME, proposal);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intentCancel, 0);

Code (full): http://pastebin.com/vNuEkBvi


What should I do?

Related questions:

PendingIntent not working when adding extras in intent

Duplicate MainActivity When Enter From Notification

1

There are 1 best solutions below

0
On BEST ANSWER

You have created intentCancel object, but tried to put extra in intent object:

Intent intentCancel = new Intent...
intent.putExtra...