Example usage for android.os Looper myLooper

List of usage examples for android.os Looper myLooper

Introduction

In this page you can find the example usage for android.os Looper myLooper.

Prototype

public static @Nullable Looper myLooper() 

Source Link

Document

Return the Looper object associated with the current thread.

Usage

From source file:Main.java

public static boolean runningOnMainThread() {
    return Looper.myLooper() == Looper.getMainLooper();
}

From source file:Main.java

public static void runOnUiThread(final Runnable runnable) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        runnable.run();/*from w ww  .  j  a  va 2  s . co  m*/
    } else {
        new Handler(Looper.getMainLooper()).post(runnable);
    }
}

From source file:Main.java

private static void checkMustInUiThread() {
    if (Looper.getMainLooper() != Looper.myLooper()) {
        throw new IllegalAccessError("this method must  call in ui thread!!");
    }/*www. jav a2s  . com*/
}

From source file:Main.java

public static void checkGLThread(String error) {
    if (Looper.getMainLooper() == Looper.myLooper()) {
        throw new RuntimeException(error);
    }//  w  w  w.  j  av  a  2s  .  c  o  m
}

From source file:Main.java

public static void checkMainThread(String error) {
    if (Looper.getMainLooper() != Looper.myLooper()) {
        throw new RuntimeException(error);
    }//from  w w  w. ja va 2 s.c om
}

From source file:Main.java

public static boolean isInMainThread() {
    Looper myLooper = Looper.myLooper();
    Looper mainLooper = Looper.getMainLooper();
    Log.i(TAG, "isInMainThread myLooper=" + myLooper + ";mainLooper=" + mainLooper);
    return myLooper == mainLooper;
}

From source file:Main.java

/**
 * @return Whether or not the current thread is the UI thread
 *///  w  w  w.  j av  a  2  s .co m
public static boolean isUIThread() {
    return (Looper.getMainLooper() == Looper.myLooper());
}

From source file:Main.java

private static void a(Context context) {
    Looper looper = Looper.myLooper();
    if (looper != null && looper == context.getMainLooper()) {
        throw new IllegalStateException("calling this from your main thread can lead to deadlock");
    } else {//from   ww w  . j a  v  a  2  s . c om
        return;
    }
}

From source file:Main.java

/**
 * @return true if we are currently in the main (UI) thread.
 *//*from w  ww.j a va2 s  . c  o m*/
public static final boolean isMainThread() {
    return Looper.getMainLooper() == Looper.myLooper();
}

From source file:Main.java

/**
 * @return true iff the current thread is the main (UI) thread.
 *//*from   w ww.j  av  a  2s.  c o m*/
public static boolean runningOnUiThread() {
    return Looper.getMainLooper() == Looper.myLooper();
}