Example usage for android.os Handler Handler

List of usage examples for android.os Handler Handler

Introduction

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

Prototype

@UnsupportedAppUsage
public Handler(boolean async) 

Source Link

Document

Use the Looper for the current thread and set whether the handler should be asynchronous.

Usage

From source file:Main.java

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

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 av a 2s .co m*/
    }.sendEmptyMessage(paramInt);
}

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   ww w .ja 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/* www.java2 s.c o m*/
        public void run() {
            Toast.makeText(context, resId, Toast.LENGTH_LONG).show();

        }
    });
}

From source file:Main.java

public static void runOnUiThread(final Runnable runnable) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        runnable.run();/*  w w w .  j  a v a2  s  .  c  o  m*/
    } else {
        new Handler(Looper.getMainLooper()).post(runnable);
    }
}

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/*  w w w  . j ava 2s  .  co m*/
 * @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 .  ja v  a  2  s. c om*/
    });
}

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//www  . j a v  a2s  . c om
        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 w w  .  ja  v  a2  s .c o  m*/
        mApplicationHandler = new Handler(Looper.getMainLooper());
        Looper.loop();
    }
    return mApplicationHandler;
}