assert Ui Thread - Android java.lang

Android examples for java.lang:Thread

Description

assert Ui Thread

Demo Code


//package com.java2s;
import static android.os.Looper.getMainLooper;
import static android.os.Looper.myLooper;

public class Main {
    static void assertUiThread() {
        if (myLooper() != getMainLooper()) {
            throw new IllegalStateException(
                    "Must be called from UI thread. Current thread: "
                            + Thread.currentThread());
        }//from ww  w  . j av  a 2s  .  com
    }
}

Related Tutorials