Handler handler = new Handler(Looper.getMainLooper());
HandlerThread handlerThread = new HandlerThread("MyHandlerThread"); handlerThread.start(); Handler handler = new Handler(handlerThread.getLooper());Here, we create a new HandlerThread object, start it, and then create a new handler that runs on that thread. This allows us to perform lengthy background tasks without blocking the UI thread. Package Library: android.os