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