25 lines
515 B
Java
25 lines
515 B
Java
package com.jc.jcfw.util;
|
|
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
|
|
public class ThreadUtils {
|
|
/**
|
|
* check if current thread is main thread
|
|
*
|
|
* @return
|
|
*/
|
|
public static boolean isMainThread() {
|
|
return Looper.getMainLooper() == Looper.myLooper();
|
|
}
|
|
|
|
public static void runInMain(Runnable action) {
|
|
if (ThreadUtils.isMainThread()) {
|
|
action.run();
|
|
} else {
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
mainHandler.post(action);
|
|
}
|
|
}
|
|
}
|