0

In my app that creates an notification icon, the click on this icon launches the main activity.

If user exits from the app thru home button and then click the notification icon then the app has 2 instances of activity and if he clicks the back button it closes the visible instance and loads the second instance of same activity. The effect is not good for the app.

I solved the problem partially by setting the Main activity as singleTask.

From my point of view the best solution would be if at the click of the notification icon the system loads the existing instance of the application without creating the new instance.

Thanks for your help!

Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63
crbin1
  • 2,219
  • 3
  • 22
  • 29
  • the question was similar than [here](http://stackoverflow.com/questions/2960459/re-open-background-application-via-notification-item), but if I find it after my post – crbin1 Sep 12 '11 at 14:20
  • Take a look at your post - there – Ken Sep 12 '11 at 23:10
  • There isn't a single question mark in your post. Therefore it's not a question. – Ken Sep 12 '11 at 23:11

1 Answers1

1

The system loads the existing instance:

In your notification to bring back the activity from stack you need to set FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY i your intent like this:

Intent notificationIntent = new Intent(context, ActivityToLaunch.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);

The app has 2 instances of activity:

you need to set singletask to the activity of which you are getting2 instances.

Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63