Timer Stops Every Time The Phone Sleeps
I'm creating this incredibly simple app, since I'm just starting with Android and I have no experience with Java what so ever. Anyhow, all I have is a timer and a button. Obviously
Solution 1:
You need to make this using BroadCastRecievers
for system-calls. (Related Helpful question)
You can also play off the life-cyles of the Activity
using the PowerManager
.
Example using PowerManager
:
@Override
protected void onPause()
{
super.onPause();
// If the screen is off then the device has been locked
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
boolean isScreenOn = powerManager.isScreenOn();
if (!isScreenOn) {
// The screen has been locked
// Continue your timer
}
}
Post a Comment for "Timer Stops Every Time The Phone Sleeps"