开发者

Click on Notification Icon [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜