revoke On Ui Thread - Android Android OS

Android examples for Android OS:Thread

Description

revoke On Ui Thread

Demo Code


//package com.java2s;
import android.os.Handler;
import android.os.Looper;

public class Main {
    private static final Object sLock = new Object();
    private static boolean sWillOverride = false;
    private static Handler sUiThreadHandler = null;

    public static void revokeOnUiThread(Runnable r) {
        getUiThreadHandler().removeCallbacks(r);
    }/*from ww w  . j  ava2  s . c  o  m*/

    public static Handler getUiThreadHandler() {
        synchronized (sLock) {
            if (sUiThreadHandler == null) {
                if (sWillOverride) {
                    throw new RuntimeException(
                            "Did not yet override the UI thread");
                }
                sUiThreadHandler = new Handler(Looper.getMainLooper());
            }
            return sUiThreadHandler;
        }
    }
}

Related Tutorials