I have a simple question: is it possible to restart (re- loop()) thread's Looper if it was previously quit. For instance, i have design my thread as follow:
public class ProvaThread extends Thread implements Runnable{
public void run(){
Looper.prepare();
Handler handler = new Handler(){
Log.d(TAG, "handle message..");
@Override
public void handleMessage(Message msg){
getLooper().quit();
}
};
Looper.loop(); //loop 1
Log.d(TAG, "thread continue (1)...");
Looper.loop(); //loop 2
Log.d(TAG, "thread continue (2)...");
}
}
I have tried this code but i get a RuntimeException
(sending message to a Handler on a dead thread) when i try to post a message to the handler the second time (handleMessage()
is not called after second loop()
). I came to conclusion that when getLooper().quit()
is called is it possible to recall loop()
but is it not possible to handle new messages, otherwise exception is thrown). Is it correct?
Should i use wait()/notify() to make this??