I want a timer to decreasing become time from current time. i.e. this is my beginning time ’05:23:23′ and if the the current time or DateTime.now() is going up my time should goes to come down, and if I am going to close the app for 05min and 13sec, and opening the app’ timer should not start from the beginning ’05:23:23′ the up should start from the passed times ’05:18:10′.
3
Answers
If I were you, I would have saved the time in a txt file, then use that for the entire process, because without saving the time somewhere, It won’t be possible for you to do what you want. I heard about Sharedpreferences which is like cache, so I would say that you can also give it a try.
To create a countdown timer that continues to decrease even when the app is closed, you can use a combination of
DateTime
andSharedPreferences
to store the remaining time when the app is closed. here is an example:time.
Time:
the app is closed.
you need to save startTime and endTime in shared preferences to save the timer when the app is closed