问题
I have 4 Activities: Launcher, MainActivity(SingleTask), NotificationActivity, ExampleActivity.
When the user clicks on the notification, NotificationActivity opens then ExampleActivity and finishes the NotificationActivity.
When I press back MainActivity opens. Now if I press back, the application gets closed. If the user then opens the app from the recent Tasks, NotificationActivity opens then ExampleActivivty. But if the user opens the app from the icon, Launcher Activity opens then MainActivity.
How to handle this situation?
回答1:
Exactly this problem is covered in my answer to this question:
Remove data from notification intent
When you select your app from the list of recent tasks, Android remembers how the app was originally launched (in your case, via Notification
) and starts the app again the same way. This can be considered a bug or a a feature, depending on what you expect to happen.
I've got a few suggestions in my answer that you can use to deal with it.
来源:https://stackoverflow.com/questions/61965236/opening-the-app-from-recents-opening-the-old-activity-in-android