I have a start and stop job method that checks to see if my connection is maintained. This is for a softphone app so the connection needs to be on as long as the user has the app opened. The code for these methods are below
public void startJob(){
mJobThread = new Thread(new Runnable() {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted() && Thread.currentThread().isAlive()) {
try {
Thread.sleep(7000);
mJobHandler.post(myJobRunnable);
} catch(InterruptedException e){
System.out.println("startJob Interrupt Runnable");
Thread.currentThread().interrupt();
return;
} catch (Exception e) {
Log.v("startJob Runnable", e.getLocalizedMessage());
}
}
}
});
mJobThread.start();
}
public void stopJob(){
if(mJobHandler != null){
mJobHandler.removeCallbacks(myJobRunnable);
}
if(mJobThread != null) {
mJobThread.interrupt();
}
}
The issue I am getting RuntimeException (nothing that crashes the application) saying
W/MessageQueue( 1946): java.lang.RuntimeException: Handler (android.os.Handler) {421ac808} sending message to a Handler on a dead thread W/MessageQueue( 1946): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:309) W/MessageQueue( 1946): at android.os.Handler.enqueueMessage(Handler.java:623) W/MessageQueue( 1946): at android.os.Handler.sendMessageAtTime(Handler.java:592) W/MessageQueue( 1946): at android.os.Handler.sendMessageDelayed(Handler.java:563) W/MessageQueue( 1946): at android.os.Handler.post(Handler.java:323) W/MessageQueue( 1946): at com.zxd.activity.Manager$5.run(Manager.java:256) W/MessageQueue( 1946): at java.lang.Thread.run(Thread.java:841)
Where line 256 is the try{
in startJob
. I call startJob
when the user logs in and stopJob
when the user logs out. I have a Service that establishes connection sometimes but that does not call startJob
or stopJob
Why am I getting this exception and what can I do to fix this?