List of usage examples for android.os Handler post
public final boolean post(Runnable r)
From source file:Main.java
/** * Function use through the app to show Toast information. Function is called so often from * background, that it's content is explicitly called from UIThread. * * @param appContext - application context * @param stringResourceId of text we show * @param handler to UIThread//from w w w .j av a 2 s . c o m */ public static void showToast(final Context appContext, final int stringResourceId, Handler handler) { handler.post(new Runnable() { @Override public void run() { Toast.makeText(appContext, appContext.getString(stringResourceId), Toast.LENGTH_SHORT).show(); } }); }
From source file:Main.java
/** * Function use through the app to show Toast information and finish current activity. * Function is called so often from background, that it's content is explicitly called from UIThread. * * @param activity - is current activity to finish * @param stringResourceId of text we show * @param handler to UIThread/*from w w w .jav a2s. co m*/ */ public static void showToastAndFinishActivity(final Activity activity, final int stringResourceId, Handler handler) { handler.post(new Runnable() { @Override public void run() { Toast.makeText(activity, activity.getString(stringResourceId), Toast.LENGTH_SHORT).show(); activity.finish(); } }); }
From source file:Main.java
public static void scrollToBottom(final ScrollView sv) { Handler handler = new Handler(); handler.post(new Runnable() { @Override/*w w w .j a va 2 s . c o m*/ public void run() { sv.fullScroll(ScrollView.FOCUS_DOWN); } }); }
From source file:Main.java
public static void displayAlert2Handler(final Context context, final String title, final String message, final String buttonText, Handler handler) { handler.post(new Runnable() { @Override//from w w w . ja v a2 s .c o m public void run() { displayAlert(context, title, message, buttonText); } }); }
From source file:Main.java
/** * Run a some task on the UI thread.//from w w w . j av a2s .c om * * @param context The context * @param r The runnable object that will be ran on the UI thread. */ public static void runOnUiThread(Context context, Runnable r) { Handler handler = new Handler(context.getMainLooper()); handler.post(r); }
From source file:Main.java
public static void run(final Runnable runnable) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override//ww w .j a va2 s. com public void run() { runnable.run(); } }); }
From source file:Main.java
static void updateTextView(Handler handler, final TextView tv, final String text) { handler.post(new Runnable() { public void run() { tv.setText(text);//from www.j a v a 2s . c o m } }); }
From source file:Main.java
/** * <p>Executes a given runnable on the main thread.</p> * * @param context An activity context.//from w ww. j av a 2 s . c o m * @param runnable A runnable to execute on the main thread. */ static void runOnMainThread(Context context, Runnable runnable) { Handler handler = new Handler(context.getMainLooper()); handler.post(runnable); }
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/*from w w w . jav a 2 s . c o m*/ public void run() { Toast.makeText(context, resId, Toast.LENGTH_LONG).show(); } }); }
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 ww w .j a va 2 s.com public void run() { Toast.makeText(context, string, Toast.LENGTH_LONG).show(); } }); }