开发者

Click on Notification Icon [closed]

开发者 https://www.devze.com 2023-04-04 12:09 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
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

精彩评论

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