Account Back in Android Studio [closed]

0

I wanted to create a countdown to a game, such as recharging lives after a while. I know how to do a countdown, the problem is that I do not know how to make it continue when leaving the application (when it closes completely, even when the cell phone restarts) Look a lot and I think the best option would be to start a count when you exit the application and when you re-enter, subtract the elapsed time from the account. Can someone give me some guidance on how to do this? Thanks

    
asked by Zekirak 09.07.2016 в 17:10
source

1 answer

1

To measure if X time has elapsed you can get the current date / time compared to a previous one

With the events onStart() and onStop() you can detect if the app is in the foreground or in the second plane. It's where you can start the countdown "second by second" and on Stop to stop the counter.

In the onCreate() event, you can get the date / time value stored in SharedPreferences so when the user returns to open the app again, follow the counter

I leave you a diagram of the life of an activity

    
answered by 10.07.2016 в 10:10