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 isInMainThread() {
    return Looper.myLooper() == Looper.getMainLooper();
}

From source file:Main.java

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

From source file:Main.java

public static boolean isMainThread() {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        return true;
    }// ww  w  . j  a  va2s  .c  o  m
    return false;
}

From source file:Main.java

public static boolean isUiThread() {
    final Looper myLooper = Looper.myLooper();
    final Looper mainLooper = Looper.getMainLooper(); // never null

    return mainLooper.equals(myLooper);
}

From source file:Main.java

public static void ensureUiThread() {
    if (Looper.getMainLooper() != Looper.myLooper()) {
        throw new RuntimeException("Invalid access, not in UI thread");
    }//from w w  w.j  a v  a2s . com
}

From source file:Main.java

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

From source file:Main.java

public static void checkBackgroudThread() {

    if (Looper.getMainLooper() == Looper.myLooper()) {
        throw new IllegalStateException("It must run in backgroud thread.");
    }//from w  ww.  j  a va 2s . c  o m
}

From source file:Main.java

public static void checkMainThread() {
    boolean error = false;
    if (Looper.myLooper() == null || Looper.getMainLooper() != Looper.myLooper()) {
        error = true;//w  w  w .j  av a  2 s .  c o m
    }

    if (error == true) {
        throw new RuntimeException("Must be in UI thread!");
    }
}

From source file:Main.java

public static boolean isMainThread() {
    if (Looper.myLooper() == null || Looper.myLooper() != Looper.getMainLooper()) {
        return false;
    }/*from   w ww  .  j  a v  a 2  s. c  o  m*/
    return true;
}

From source file:Main.java

public static void runOnUiThread(final Runnable runnable) {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        new Handler(Looper.getMainLooper()).post(runnable);
    } else {//from  w  w w  . j  av  a 2s.  com
        runnable.run();
    }
}