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

posted @ 2016-10-05 09:02  googlg  阅读(4992)  评论(0编辑  收藏  举报