Search code examples
androidrunnable

Runnable update lag


My app is a basic clock and i use Runnable for updating the time and the Drawable, but it seems to have some lag in every minute its like 2 or 3 times, its freeze for aboute 2 sec. This is my runnable code:

private Runnable updateTimeTask = new Runnable() {
    public void run() {
    updateTime();
    handler.postDelayed(this, 1000);
    }

Dose someone know what method to use, or how to fix this issue, its not fine for the clock to have missing seconds and drawable lag.


Solution

  • The delay is probably the amount of time it takes to process updateTime(). Try starting the new timer before you call updateTime().

    private Runnable updateTimeTask = new Runnable() {

    public void run() {
    
    handler.postDelayed(this, 1000);
    updateTime();
    }