How to check if current thread is not main thread
Looper.myLooper() == Looper.getMainLooper()
if this returns true, then you're on the UI thread!
you can use below code to know if current thread is UI/Main thread or not
if(Looper.myLooper() == Looper.getMainLooper()) {
// Current Thread is Main Thread.
}
or you can also use this
if(Looper.getMainLooper().getThread() == Thread.currentThread()) {
// Current Thread is Main Thread.
}
Here is similar question