Click on Notification Icon [closed]
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!
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.
精彩评论