I am making an Android app that has a time limit to the amount of points you can get. But if you close the app, the timer keeps going. How do I pause the CountDownTimer
when the app pauses?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
You can cancel it in
onPause()
with something likeAnd use the
millisUntilFinished
variable to save in aSharedPreference
or some other persistent variable. Then use that variable again to start the timer inonResume()
Shared Prefs
This answer may be helpful if you need to pass the value to another
Activity
.