天天看點

android 判斷目前線程是否是主線程

public class ThreadUtils{

	// 方法1
	public static boolean isMainThread() {
	    return Looper.getMainLooper() == Looper.myLooper();
	}
	
	// 方法2
	public static boolean isMainThread() {
	    return Looper.getMainLooper().getThread() == Thread.currentThread();
	}
	
	// 方法3
	public static boolean isMainThread() {
	    return Looper.getMainLooper().getThread().getId() == Thread.currentThread().getId();
	}
}