Android 判断当前thread 是否是UI thread


   在Android 中判断当前的Thread是否是UI Thread 的方法:

  1.    

if (Looper.myLooper() == Looper.getMainLooper()) {
    // Current thread is the UI/Main thread
}        
 

  2.

if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
    // Current thread is the UI/Main thread
}

 

 参考如下文章:其中还讲到了  runOnUiThread()  方法的用法。

http://codetheory.in/checkdetect-whether-current-thread-uimain-thread-android/

http://lak4cyut.blogspot.jp/2011/03/android-tip-activityrunonuithread.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM