I have a Runnable
inside an Android Service and the service is bound to an activity.
The problem is that when the screen gets locked, the runnable
pauses. It resumes after the screen is unlocked.
Following is the code for the runnable -
private Runnable counterRunnable = new Runnable() {
@Override
public void run() {
totalTime = SystemClock.uptimeMillis() - lngStartTime;
totalTime += lngPauseTime;
strMillis = String.valueOf(((Integer.valueOf(String.valueOf(totalTime))) / 10) % 60);
strSecs = String.valueOf(((Integer.valueOf(String.valueOf(totalTime))) / 1000) % 60);
strMins = String.valueOf((((Integer.valueOf(String.valueOf(totalTime))) / 1000) / 60) % 60);
strHrs = String.valueOf(((((Integer.valueOf(String.valueOf(totalTime))) / 1000) / 60) / 60) % 60);
if(strMillis.length() == 1)
strMillis = "0" + strMillis;
if(strSecs.length() == 1)
strSecs = "0" + strSecs;
if(strMins.length() == 1)
strMins = "0" + strMins;
if(strHrs.length() == 1)
strHrs = "0" + strHrs;
Log.i(TAG, strHrs + ":" + strMins + ":" + strSecs + ":" + strMillis);
hndlrUpdateTime.postDelayed(this, 10);
}
};
I want to know the reason why the runnable
is pausing when the screen pauses.