在Android 中判断当前线程是否是主的方法:
代码使用kotlin写的,所以判断String用的 ‘==’
//是否为主线程
if (Thread.currentThread().name == "main") {
}
//是否为主线程
if (Looper.myLooper() == Looper.getMainLooper()) {
}
//是否为主线程
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
}
网友评论