如何检查是否当前线程不是主线程 [英] How to check if current thread is not main thread
本文介绍了如何检查是否当前线程不是主线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要检查,如果运行的某一块code线程的主(UI)线程上运行与否。我怎样才能做到这一点?
解决方案
Looper.myLooper()== Looper.getMainLooper()
如果返回true,那么你是在UI线程!
I need to check if the thread running a certain piece of code is running on the main (UI) thread or not. How can I achieve this?
解决方案
Looper.myLooper() == Looper.getMainLooper()
if this returns true, then you're on the UI thread!
这篇关于如何检查是否当前线程不是主线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文