I have a HandlerThread to which I continue to publish runnable every 5 seconds. Something like that:
HandlerThread thread = new HandlerThread("MyThread"); thread.start(); Handler handler = new Handler(thread.getLooper()); handler.post(new Runnable() { public void run() {
I need to get out of the looper at some point, after 60 seconds or something like that. Therefore, I write:
mainHandler = new Handler(Looper.myLooper());
I think this causes the looper to abruptly stop working, so I start to receive “warning” messages:
W / MessageQueue (3726): java.lang.RuntimeException: Handler (android.os.Handler) {4823dbf8} sends a message to the dead thread handler
I want to avoid this msg error, I thought I could solve it using the Looper.quitSafely() method .. but I checked the API and it is no longer available. Does anyone know what happened to him? (It is not outdated, like some other methods).
Is there a way so that I can safely leave the looper? Thanks!
android looper handlers
sundie
source share