How to check if current thread is not main thread

Charlie-Blake picture Charlie-Blake · Jul 10, 2012 · Viewed 128.1k times · Source

I need to check if the thread running a certain piece of code is the main (UI) thread or not. How can I achieve this?

Answer

Carnal picture Carnal · Jul 10, 2012
Looper.myLooper() == Looper.getMainLooper()

if this returns true, then you're on the UI thread!