Android 判断当前线程是否是主线程的方法

方法一:
public boolean isMainThread() {
    return Looper.getMainLooper().getThread() == Thread.currentThread();
}


方法二:
public boolean isMainThread() {
Looper looper = Looper.myLooper();
if (looper == null) {
      return false;
        }
 return  looper == Looper.getMainLooper()  ;
}

猜你喜欢

转载自blog.csdn.net/banzhuantuqiang/article/details/134041684
今日推荐