开发过程中,我们需要知道当前的线程是否为UI线程(主线程),在这里有两个简单的方法判断,但是本质上是一样的
1,根据Lopper.myLooper 判断:
private boolean isMainThread()
{
return Looper.getMainLooper() == Looper.myLooper();
}
2,根据Looper 获取的Thread 判断:
private boolean isMainThread()
{
return Looper.getMainLooper().getThread() == Thread.currentThread();
}
这两种方法本质是一样的。