下面三个方法都可以判断当前线程是否在主线程
1
public boolean isMainThread() {
return Looper.getMainLooper() == Looper.myLooper();
}
2
public boolean isMainThread() {
return Looper.getMainLooper().getThread() == Thread.currentThread();
}
3
public boolean isMainThread() {
return Looper.getMainLooper().getThread().getId() == Thread.currentThread().getId();
}