androidcountdowntimeractivity-state

How to keep the activity state intact on back press in android?


I am new to Android . As per the Android Developers Doc making an activity launchmode singleTop it will keep that activity intact . But its not working for me .I have an Activity where i have a countdown timer , what i want is when i leave that Activity on back press and return to that Activity that countdown timer should still be running . How to do it ? Please Help


Solution

  • I believe you misunderstood a bit.

    Launching an activity in singleTop does not mean that the activity is "intact", it means that if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent - a new instance won't be created. (This is opposite to launching activities in standard mode, which every time there's a new intent a new instance of the class is created to respond to that intent.)

    As others suggested, you could bind to a Service and update the countdown time from there.