Suppose I have a HandlerThread
in Application
class which I use to do some background work. Do I need to stop this thread myself or will it be killed by OS along with Application
instance? My code looks something like this.
public class MyApplication extends Application {
private Handler handler;
@Override
public void onCreate() {
super.onCreate();
HandlerThread handlerThread = new HandlerThread("WorkerThread");
handlerThread.start();
this.handler = new Handler(handlerThread.getLooper());
}
public void runInBackground(Runnable runnable) {
this.handler.post(runnable);
}
}