0

I'm using the following intent with a notification and the issue is that if the current activity is the same as the intent nothing happens. How do I open the same activity with the new data?

intent = new Intent(context, PackViewActivity.class);
                                intent.putExtra("pid", pack_id);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

Here is the details fromt he Manaifest:

<activity
        android:name=".PackViewActivity"
        android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
        android:launchMode="singleTask"/> //I've also tried singleInstance with no success.

Currently everything works fine unless the current activity is PackViewActivity. In that case nothing happens.

jampez77
  • 5,012
  • 7
  • 32
  • 52

2 Answers2

1

Like @Vivek mentioned, use Intent.FLAG_ACTIVITY_CLEAR_TOP and remove Intent.FLAG_ACTIVITY_CLEAR_TASK. Now, if your activity is already running the new intent will be delivered in onNewIntent(). That is where you should put your intent reading code. Also, get rid of android:launchMode in your activity manifest description since it brings a lot of problems with it.

Shaishav
  • 5,282
  • 2
  • 22
  • 41
1

If the required activity is already in foreground then you need not to push a notification. Alternatively you can register the activity as a listener to the service or activity class which pushes the notification through NotificationManager. Then handle the notification appropriately.