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 scheduleDelayedTask(Runnable task, long delay) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.postDelayed(task, delay);/*  ww w  . ja v a  2 s.  co m*/
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static Handler getMainHandler() {
    if (handler == null) {
        handler = new Handler(Looper.getMainLooper());
    }/*w w  w.  j ava2 s  . c  om*/
    return handler;
}

From source file:Main.java

private static Handler getHandler() {
    if (mHandler == null) {
        mHandler = new Handler(Looper.getMainLooper());
    }//  w ww  .j  a  v  a  2 s .  co  m
    return mHandler;
}

From source file:Main.java

/**
 * @return true if we are currently in the main (UI) thread.
 *///w w  w.  ja v a  2s.  co m
public static final boolean isMainThread() {
    return Looper.getMainLooper() == Looper.myLooper();
}

From source file:Main.java

public static void setViewVisibilityOnMainThread(final View paramView, int paramInt) {
    new Handler(Looper.getMainLooper()) {
        public void handleMessage(Message paramAnonymousMessage) {
            paramView.setVisibility(paramAnonymousMessage.what);
        }//from w w  w  .j  ava2  s .com
    }.sendEmptyMessage(paramInt);
}

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

public static void toast(final String s, final Context context) {

    Handler handler = new Handler(Looper.getMainLooper());

    handler.post(new Runnable() {

        @Override//from   w ww .j  a  v a 2  s. co  m
        public void run() {
            Toast.makeText(context, s, Toast.LENGTH_SHORT).show();

        }
    });
}

From source file:Main.java

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

    handler.post(new Runnable() {

        @Override// w  ww . j  a  v  a2 s  .  c  o m
        public void run() {
            Toast.makeText(context, resId, Toast.LENGTH_LONG).show();

        }
    });
}