Last Updated: February 13, 2015

Android:How to find on which thread code is exceuting?

As we normally say it code is running in “background thread or UI thread”.

Question: How to find on which thread the code is executing?
This article helps to find on which thread the code is executing in Android.

public static boolean isFromMainThread(){
        return Looper.getMainLooper().getThread().getId() == Thread.currentThread().getId();

Example with thread:
As we say that thread exceute in seperate thread here is the proof:

Thread thread = new Thread(new Runnable() {
                public void run() {
                    if (isFromMainThread()) {
                        Log.d("Fetch", " Runnable Executing From Main Thread");
                    } else {
                        Log.d("Fetch", " Runnable Executing From Background Thread");



  1. Good morning! Our platform focus on keeping our prices low, but unlike other academic writing services online, we never sacrifice quality for the sake of price. We thrive on service orientation; our mission is to increase customer loyalty by providing nonparallel services and after sales support.

  2. Nice content thanks for sharing this information with us i hope you keep writing content like this in future. Yellowstone Vest


Your comments are valuable for us !!!