Java tutorial
//package com.java2s; //License from project: Apache License import android.os.Handler; import android.os.HandlerThread; import android.support.annotation.NonNull; public class Main { /** * Get a Handler that is running on a background thread. * NOTE!!! The HandlerThread that is passed as a param MUST be stopped via * handlerThread.quitSafely() or handlerThread.quit(); * @param handlerThread {@link HandlerThread}Cannot be null since this will start * the thread when it is passed. * @return {@link Handler} */ public static Handler getBackgroundHandler(@NonNull HandlerThread handlerThread) { handlerThread.start(); Handler handler = new Handler(handlerThread.getLooper()); return handler; } }