List of usage examples for android.os Handler post
public final boolean post(Runnable r)
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 w w . ja v a2s .c om*/ public void run() { Toast.makeText(context, s, Toast.LENGTH_SHORT).show(); } }); }
From source file:Main.java
public static void postOnUi(Context ctx, Runnable task) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(task); }
From source file:Main.java
public static void runOnUiThread(Runnable runnable) { final Handler UIHandler = new Handler(Looper.getMainLooper()); UIHandler.post(runnable); }
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 w w . j a v a 2s. 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
/** * Schedule a toast message to be shown via supplied handler. * * @param handler the handler the toast should be scheduled to * @param id string resource id for the message text * @param duration toast duration constant *///from w w w .j a va2 s .c o m public static void showToast(final Context ctx, final Handler handler, final int id, final int duration) { handler.post(new Runnable() { public void run() { Toast.makeText(ctx, id, duration).show(); } }); }
From source file:Main.java
/** * Schedule a toast message to be shown via supplied handler. * * @param handler the handler the toast should be scheduled to * @param text string for the message text * @param duration toast duration constant *//* ww w. ja v a 2 s . c om*/ public static void showToast(final Context ctx, final Handler handler, final String text, final int duration) { handler.post(new Runnable() { public void run() { Toast.makeText(ctx, text, duration).show(); } }); }
From source file:com.amalgam.app.DialogFragmentUtils.java
public static final void dismissOnLoaderCallback(Handler handler, final FragmentManager manager, final String tag) { handler.post(new Runnable() { @Override/* ww w. ja va 2 s . c o m*/ public void run() { DialogFragment fragment = (DialogFragment) manager.findFragmentByTag(tag); if (fragment != null) { fragment.dismiss(); } } }); }
From source file:com.amalgam.app.DialogFragmentUtils.java
public static final void showOnLoaderCallback(Handler handler, final FragmentManager manager, final DialogFragment fragment, final String tag) { handler.post(new Runnable() { @Override/*from w w w.j a va 2 s . com*/ public void run() { fragment.show(manager, tag); } }); }
From source file:Main.java
public static Timer setInterval(final Runnable runnable, int delayMillis, int period) { final Handler handler = new Handler(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override/*from w ww .j av a2s . co m*/ public void run() { handler.post(runnable); } }, delayMillis, period); return timer; }
From source file:Main.java
public static Timer setTimeOut(final Runnable runnable, int delayMillis) { final Handler handler = new Handler(); final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override/* w w w . j a v a2 s . co m*/ public void run() { handler.post(runnable); timer.cancel(); } }, delayMillis); return timer; }