List of usage examples for android.os Handler Handler
@UnsupportedAppUsage public Handler(boolean async)
From source file:Main.java
public static void showToast(Context context, String message) { new Handler(Looper.getMainLooper()).post(() -> { Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); });/*from w ww. ja v a 2 s. c o m*/ }
From source file:Main.java
public static void showKeyboard(final View view) { new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override//from www . j a v a 2s .c om public void run() { setKeyboardVisible(view, true); } }, 200); }
From source file:Main.java
public static void runOnUI(Runnable runnable) { if (handler == null) { handler = new Handler(Looper.getMainLooper()); }/*from www .j a v a2 s .c o m*/ handler.post(runnable); }
From source file:Main.java
public static void postOnUi(Context ctx, Runnable task) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(task);//w w w . ja va 2 s .c o m }
From source file:Main.java
/** * Execute a runnable in the given looper * @param looper Looper to run the action. * @param action The code to run.// w w w.j a va2 s. c o m */ public static void runOnLooper(Looper looper, Runnable action) { new Handler(looper).post(action); }
From source file:Main.java
/** * Run the Runnable "delayed" by using an AsyncTask to first require a new * thread and only then, in onPostExecute, run the Runnable on the UI thread. * @param runnable Runnable to run on UI thread. *///from w ww . ja va 2 s . c o m public static void runUiDelayed(final Runnable runnable) { (new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... arg0) { return null; } /** * Always invoked on UI thread. */ @Override protected void onPostExecute(Void result) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(runnable); } }).execute(); }
From source file:Main.java
/** * Execute the given {@link Runnable} on the ui thread. * * @param runnable The runnable to execute. *///from w w w. j a v a 2 s.c o m public static void runOnUiThread(Runnable runnable) { Thread uiThread = Looper.getMainLooper().getThread(); if (Thread.currentThread() != uiThread) new Handler(Looper.getMainLooper()).post(runnable); else runnable.run(); }
From source file:Main.java
public static void postOnUi(Context ctx, Runnable task, long delayMs) { Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(task, delayMs);/* ww w . j ava2 s. c o m*/ }
From source file:Main.java
private static Handler sharedHandler(Context context) { if (mHandler == null) { mHandler = new Handler(context.getMainLooper()); }//from ww w . j av a 2s . c om return mHandler; }
From source file:Main.java
public static void runOnUiThread(Runnable runnable) { final Handler UIHandler = new Handler(Looper.getMainLooper()); UIHandler.post(runnable);//from ww w . j a v a2 s. co m }