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

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

From source file:Main.java

public static boolean isMain() {
    return Looper.getMainLooper().getThread() == Thread.currentThread();
}

From source file:Main.java

public static void scheduleOnMainThread(Runnable r, long delay) {
    new Handler(Looper.getMainLooper()).postDelayed(r, delay);
}

From source file:Main.java

/**
 * Get the Main Thread looper//from   w w  w. j a v a2  s .  com
 * @return {@link Handler}
 */
public static Handler getMainHandler() {
    Handler handler = new Handler(Looper.getMainLooper());
    return handler;
}

From source file:Main.java

public static void showToast(final Context c, final CharSequence text) {
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        public void run() {
            if (c == null)
                return;
            Toast.makeText(c, text, Toast.LENGTH_SHORT).show();
        }//from   w ww  .j a v  a  2s .  com
    });
}

From source file:Main.java

private static void showToast(final Context context, final String string) {
    Handler handler = new Handler(Looper.getMainLooper());

    handler.post(new Runnable() {

        @Override/*from w  w w  .ja  v a2 s  . c  o  m*/
        public void run() {
            Toast.makeText(context, string, Toast.LENGTH_LONG).show();

        }
    });
}

From source file:Main.java

public static Handler getApplicationHandler(Runnable runnable) {
    if (mApplicationHandler == null) {
        Looper.prepare();/*  w  ww .j a  v  a  2s  .  co  m*/
        mApplicationHandler = new Handler(Looper.getMainLooper());
        Looper.loop();
    }
    return mApplicationHandler;
}

From source file:Main.java

public static boolean isUIThread() {
    return Thread.currentThread().equals(Looper.getMainLooper().getThread());
}

From source file:Main.java

/**
 * This class will determine if the current loop being run is on the main thread or not
 * @return boolean, true if on main ui thread, false if not
 *//*from   www .ja  v  a  2 s.c  o m*/
public static boolean isRunningOnMainThread() {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        return false;
    } else {
        return true;
    }
}

From source file:Main.java

public static Handler getMainThreadHandler() {
    if (mMainHandler == null) {
        mMainHandler = new Handler(Looper.getMainLooper());
    }//  ww  w.j av a2s  .  c  om
    return mMainHandler;
}