I have a thread that uses a handler and messages to send data to an action. Everything works fine, except when the action is paused:
null sending message to a Handler on a dead thread
java.lang.RuntimeException: null sending message to a Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:196)
at android.os.Looper.quit(Looper.java:173)
at pocket.net.ComD.stopConnection(ComD.java:154)
at pocket.net.ComD.finalize(ComD.java:184)
at dalvik.system.NativeStart.run(Native Method)
In my activity, I have the following code that allows me to close the entire network connection opened by the stream:
public void onPause()
{
if(this.myThread != null) {
this.myThread.stopConnection();
}
}
In my topic:
public void run()
{
this.setName("MessagesThread");
if(this.initSocket())
{
Looper.prepare();
this.threadHandler = initHandler();
Looper.loop();
}
else
{
this.timeout();
}
}
public void stopConnection()
{
if(this.threadHandler != null) {
this.threadHandler.removeMessages(ALIVE);
this.threadHandler.getLooper().quit();
}
this.connected = false;
if(this.client != null) {
this.client.close();
}
}
private Handler initHandler()
{
return new Handler() {
public void handleMessage(Message msg)
{
switch(msg.what)
{
}
}
}
}
When I get the warning "send message" null for handler in a dead thread "is this an action that tries to send a message to a stream or oppposite?
How can i fix this?
thank
source
share