How to detect UI thread on Android? -


Is there a strong way to find out that Thread.currentThread () Android System UI Thread In an application?
I want to emphasize in my model code which claims that only one thread ( like ui thread) reaches my state, to ensure that no synchronization is necessary

Common practice is to determine the identity of the UI thread:

 < Code> if (Looper.getMainLooper (). GetThread () == thread. CurrentThread ()) {// on UI thread. } Else {// not on the UI thread. }  

Comments