1. 运行在主线程
public class ThreadUtils {/** * Run a runnable on the Main (UI) Thread. * @param runnable the runnable */ public static void runOnUiThread(final Runnable runnable) { if (Looper.myLooper() != Looper.getMainLooper()) { new Handler(Looper.getMainLooper()).post(runnable); } else { runnable.run(); } } /** * Returns {@code true} if called on the main thread, {@code false} otherwise. */ public static boolean isOnMainThread() { return Looper.myLooper() == Looper.getMainLooper(); } }