I’m starting a Timer on the first screen of my app. The problem comes from when the phone goes to sleep. The action that the Timer triggers cannot access the network and make the app crash.
The solution for me would be to stop/restart the timer when the phone goes to sleep.
So are there any methods I can implement like onLowMemory() or onTerminate() from the Application class. onSleep() and onWake() would be good 🙂
In the
Activitycode for your first screen you can overrideonStoporonPauseand cancel your timer there. Choose whichever one works best for your purposes.You can then re-start your timer when
onResumeoronStartis called.