美文网首页Android自解
Android 当前线程是否为主线程(UI线程)

Android 当前线程是否为主线程(UI线程)

作者: 清柠茶 | 来源:发表于2019-08-26 17:16 被阅读0次

在Android 中判断当前线程是否是主的方法:
代码使用kotlin写的,所以判断String用的 ‘==’

//是否为主线程
if (Thread.currentThread().name == "main") {
}
//是否为主线程
if (Looper.myLooper() == Looper.getMainLooper()) {
}     
//是否为主线程
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
}

相关文章

网友评论

    本文标题:Android 当前线程是否为主线程(UI线程)

    本文链接:https://www.haomeiwen.com/subject/dtrdectx.html