0

I have 3 activities in my app: A, B, C. A launches B, B launches C. C's launch mode is SingleInstance(declared in manifest).

Steps: 1.When I am on C, I show notification in notification bar, onclick of which launch same screen. 2. I put my app in background by pressing home. 3. When I tap on notification, C gets launched.

Question: When I press back on C, I come out of my application. Instead, I should go back to earlier screen of my app, i.e. B

Note: I have declared C as singleInstance, because I don't want multiple instances of C getting launched on tap of notification. I have handled same instance, with OnNewIntent(), by refreshing UI with corresponding data.

Thanks in advance!

David Wasser
  • 93,459
  • 16
  • 209
  • 274
Virat18
  • 3,427
  • 2
  • 23
  • 29

1 Answers1

1

Use the default launch mode of standard for Activity C.

In the intent used to build the PendingIntent for your notification, add flag FLAG_ACTIVITY_SINGLE_TOP:

Intent intent = new Intent(this, ActivityC.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

The existing instance of activity C will be resumed and the onNewIntent() method called.

Bob Snyder
  • 37,759
  • 6
  • 111
  • 158