Pillager225
Pillager225

Reputation: 438

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.

Upvotes: 1

Views: 140

Answers (2)

MarchingHome
MarchingHome

Reputation: 1204

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()

Upvotes: 0

Tolga E
Tolga E

Reputation: 12678

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

Upvotes: 1

Related Questions