javaandroidwear-osandroid-wear-notification

Android Wear: Resume previous activity state from notification


I have an Android Wear app that contains an activity with a timer and a view rendered accordingly. When a user swipes right on the activity to get back to the Context Stream a notification appears showing that the App is still counting.

However the user is unable to resume the timer activity from the notification intent because a brand new instance of this activity is launched. I know there is a FLAG_ACTIVITY_REORDER_TO_FRONT flag I can add to the intent but because activity is destroyed when the user swipes right on it, this does not work.

How can I properly resume the activity from the notification. I guess I somehow need to prevent it being destroyed on swiping back?

Thanks in advance!


Solution

  • Once you leave the app, your activities will be destroyed, so you will have to save the time you started the timer somewhere (Shared Preferences is a good option), and then read this in when your app is restarted.