简体   繁体   中英

Application resuming through the Notification bar

I have an application that starts a timer and an ongoing notification. Whenever I click on the notification though it doesn't continue the old time, but instead creates an identical activity on top of the first where the timer is as it was before the user started the timer. If I hit the back button or programatically use the finish(); command then it will go back to the old timer where the time was still running and had not stopped running. In essence, I am asking how do you make it so that when you click the notification for the application that you ensure that it takes you back to the way the application was left rather than its original state? Please help. If needed I can provide sample code.

If you change the activities LaunchMode (in AndroidManifest.xml) to singleTask (android:launchMode="singleTask") it should resolve your problem. This will make sure that there's only one instance of this activity.

Also you might want to read through the activity documentation here When you scroll down, there's information of lauchModes

You can also do this by specifying flags with the intent. There are multiple questions of the same kind already answered here at SO. See the "related questions". For example: Android: How to avoid that clicking on a Notification calls onCreate()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM