1.是否在主线程判断
/** Returns {@code true} if called on the main thread, {@code false} otherwise. */
public static boolean isOnMainThread() {
return Looper.myLooper() == Looper.getMainLooper();
}
/** Returns {@code true} if called on a background thread, {@code false} otherwise. */
public static boolean isOnBackgroundThread() {
return !isOnMainThread();
}
网友评论