Delay in Thread execution+Android
<p>After many trials of solutions (including posting questions on SO) I thouht will work fine. But no improvement. Coming to my problem, I am implementing an App that have a countdown timer. I am showing this on a button (Just using like a canvas by disabling the click event). 
I start the timer when user clicks a button (which is a separate button). Below is the countdown timer code,</p>

<pre><code>public class DigitalTimer extends Button{

--------------------------------    
--------------------------------    
--------------------------------    
--------------------------------    
--------------------------------    
--------------------------------    
private String timerText;
public DigitalTimer (Context context,int hourstime,int mintime,int sectime){
    super(context);
    Log.d(TAG,"DigiTimer constructor");     
    this.context = context;     
    initialize(hourstime,mintime,sectime,timerType);
    setClickable(false);
}

public void initialize(int hourstime,int mintime,int sectime,int timerType){
    Log.d(TAG,"DigiTimer initialize");      
    this.hourstime = hourstime;
    this.mintime = mintime;     
    hour = hourstime;
    min = mintime;
    sec = sectime;

    //Just Thread version               
    **digiThread = new Thread(){
        @Override
        public void run(){
            while(!isPauseTimer()){
                updateTimes();
                SystemClock.sleep(UPDATEDELAY);
            }

        }           
    };**


    //Handler version       

    /*
    handleRunnable = new Runnable(){
        public void run(){
            updateTimes();
        }
    };
    */

}

private void updateTimes(){

    timerText = String.format(timerFormat,hour,min,sec );       
    postInvalidate(); 
    sec--;
    if(sec &lt; 0){
        sec = 59;
        min--;
    }
    if(min &lt; 0){
        min = 59;
        hour--;
    }   

    if(hour &lt; 0){  //when hour is negative it means the given time completed so we stop the timer &amp; alarm permanantely 
     hour = 0;
     min = 0;
     sec = 0;
          }

}
@Override
protected void onDraw(Canvas canvas){
    super.onDraw(canvas);
    Log.d(TAG,"DigiTimer onDraw");      
    setBackgroundResource(R.drawable.button9patch);     
    setText(timerText);     
}
public void startUpdateTheread(){
    //digiHandler.postDelayed(handleRunnable, UPDATEDELAY);
    **digiThread.start();**
}


private void startTimersAndAlarms(){
 -----------------------
 -----------------------
 -----------------------
 -----------------------
 **startUpdateTheread();**
 ---------------------
 ---------------------

}
</code></pre>

<p>}   </p>

<p>Initially the timer is woking fine . <strong>But if no.of hours for the countdown is higher (say 5:00:00) then its running fine until sometime (say 4:00:00) from then it is delaying the timer update</strong>. (just to countdown a minute it is taking more time ..particularly when the user is out of the App)
    First I tried with the Handler. I had the problem. I thought the delay is because of keeping the UI thread busy. So I developed a separate thread. But still the problem persist.</p>

<p>Sorry for the long post. Please someone point what's happening. Is that something I am missing or putting the code in wrong place?</p>

<p>Thanks</p>

<p><strong>EDIT:</strong> I read SystemClock.sleep documentation. It says "{This clock stops when the system enters deep sleep (CPU off, display dark, device waiting for external input) }". I understand  that I should keep CPU on while I run this thread. So according to the answer by @Brandon I should implement partial POWERLOCK to keep the CPU on. Is my understanding correct?</p>
