Handler to show the countdown timer is not reliable
<p>I am developing an App where I show the countdown timer. To countdown the time I am using Handler class. Once the countdown timer reaches certain time the Alarm goes off. My problem is as below,
        Initially I show the timer time as 04:00:00. Once it reaches 00:00:00 then the Alarm goes off. The Alarm code is working fine. But the timer display is not reliable. It works fine until I keep the App open. If I close the App (using Home or Back) or lock the device and open App again then the timer shown is not the correct one (delaying a lot, but still alarm works on-time). (But it works sometimes very fine under the same scenario). But whenever I ping the device to the system for checking the Log in eclipse that time all works fine!!!!!!!</p>

<pre><code> 1. I want to know whether I am using the Handler properly or not
 2. (or) Is going out of the App or locking the device causing the problem
</code></pre>

<p>Below is my Handler code,</p>

<p>Handler digiHandler;</p>

<p>// Method to initialize the time and define the Handler</p>

<pre><code>public void initialize(int hourstime,int mintime,int sectime){
    hour = hourstime;
    min = mintime;
    sec = sectime;
    digiHandler = new Handler();
    handleRunnable = new Runnable(){
        public void run(){
            updateTimes();
        }
    };
}


public void startUpdateTheread(){
    digiHandler.postDelayed(handleRunnable, UPDATEDELAY);
}       

// Method to update the timer times

private void updateTimes(){

    timerText = String.format(timerFormat,hour,min,sec );
    -------------------------
    -------------------------
    --  code for incrementing the time ---
    --------------------------
    --------------------------
    --------------------------

        startUpdateTheread();           
}
</code></pre>

<p>Please give the suggestions</p>

<p>Thanks</p>

<p><strong>Edit:</strong> 
  When I observed the log it shows that to countdown 1 second of timer sometimes it is taking 1 minute time. The log is as below,</p>

<p>09-21 <strong>21:09:18.965</strong>: DEBUG/DigitalTimer(7656): timerText**:<strong>04:22:54</strong></p>

<pre><code>    ****long difference here****
</code></pre>

<p>09-21 <strong>21:10:19.308</strong>: DEBUG/DigitalTimer(7656): timerText**:<strong>04:22:53</strong></p>

<p>..................................................................................
..................................................................................
..................................................................................</p>

<p>09-21 <strong>21:10:23.314</strong>: DEBUG/DigitalTimer(7656): timerText**: <strong>04:22:49</strong></p>

<pre><code>    **--long difference here ---**
</code></pre>

<p>09-21 <strong>21:11:22.604</strong>: DEBUG/DigitalTimer(7656): timerText**:<strong>04:22:48</strong></p>

<p>It is happening always. So I can rule out that locking/coming out of an App is causing the  problem. Seems I need to tweak the Handler part of the code.</p>
