版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dhl_1986/article/details/82348679
开发过程中,我们需要知道当前的线程是否为UI线程(主线程),在这里有两个简单的方法判断,但是本质上是一样的
1,根据Lopper.myLooper 判断:
private boolean isMainThread()
{
return Looper.getMainLooper() == Looper.myLooper();
}
2,根据Looper 获取的Thread 判断:
private boolean isMainThread()
{
return Looper.getMainLooper().getThread() == Thread.currentThread();
}