2

I have an activity in my app which can be opened thanks to a notification. But the content of the activity depends on the kind of notification. For example : If I receive a 'a notification', the app launch the activity and this one displays 'a received'. Then, if I receive a 'b notification', the app launch the activity again and displays 'b received'. The probleme is that when the activity has already been launched once, when the 'b notification' relaunch it again, the activity still displays 'a received'. How could I force the activity to re-create depending on the Intent received?

I tried intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); but that doesn't work.

Thanks !

EDIT : after some research, I've found out that the pendingIndent was the problem. It seems that the intent passed as a parameter in PendingIntent.getActivity(ctx, 0, intent, 0) wasn't updated. I just added

intent.setAction(Long.toString(System.currentTimeMillis()));

and everything worked like a charm.

Romain Pellerin
  • 2,470
  • 3
  • 27
  • 36

2 Answers2

0

Finish any existing activity in 'A' or 'B' notification handler before starting the activity.

Chandru
  • 121
  • 1
  • 4
0

call finish() when you want to relaunch the app and then override onDestroy() and do the following.

@override
public void onDestroy()
{
   startActivity(new Intent(this,ThisDyingAcitivity.class));
}
Umer Farooq
  • 7,356
  • 7
  • 42
  • 67