Example usage for android.os Looper getMainLooper

List of usage examples for android.os Looper getMainLooper

Introduction

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

Prototype

public static Looper getMainLooper() 

Source Link

Document

Returns the application's main looper, which lives in the main thread of the application.

Usage

From source file:Main.java

public static void scheduleOnMainThread(Runnable r) {
    new Handler(Looper.getMainLooper()).post(r);
}

From source file:Main.java

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

From source file:Main.java

public static void checkMainThread(String error) {
    if (Looper.getMainLooper() != Looper.myLooper()) {
        throw new RuntimeException(error);
    }/*from ww w .j a v  a 2  s  . c o m*/
}

From source file:Main.java

public static void gcDelay(long delay) {
    new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
        @Override//from   w w w  . j  a va2s.c  o m
        public void run() {
            gc();
        }
    }, delay);
}

From source file:Main.java

public static void run(final Runnable runnable) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override/*from   w w  w.  ja  va  2  s  . co  m*/
        public void run() {
            runnable.run();
        }
    });
}

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 a va  2 s  .c  o  m*/
        runnable.run();
    }
}

From source file:Main.java

public static void checkMainThread() {
    boolean error = false;
    if (Looper.myLooper() == null || Looper.getMainLooper() != Looper.myLooper()) {
        error = true;//from  ww  w  . ja v  a  2 s  . c om
    }

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

From source file:Main.java

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

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 runOnUiThread(final Runnable runnable) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        runnable.run();//from   w ww  . ja v a 2s  .co  m
    } else {
        new Handler(Looper.getMainLooper()).post(runnable);
    }
}