This problem drives me crazy. I miss some basic but very important knowledge about how to handle long operations in a new thread created within an activity and how to modify
Just a quick idea.
i think, it's your toast-messages within thread. Try to comment them out.
If you still want to show messages, save the status of your thread and handle it in your handler. Call for that your handler from finally block
mProgressDialog = ProgressDialog.show(mContext, "Tripplanner", "please wait...", true, false);
connectAndGetRoute();
private void connectAndGetRoute(){
new Thread(){
@Override
public void run() {
try {
if(!connectTo9292ov()) return;// conncetto9292ov() connects to a website, parses the reasult into an arraylist. The arraylist contains route.
} catch(UnknownHostException e){
// an int member of your activity
threadStatus = 404;
// Toast.makeText(mContext, "failed to connect to server", Toast.LENGTH_LONG).show();
}catch (ClientProtocolException e) {
threadStatus = 404;
// Toast.makeText(mContext, "failed to connect to server", Toast.LENGTH_LONG).show();
} catch (IOException e) {
threadStatus = 404;
// Toast.makeText(mContext, "failed to connect to server", Toast.LENGTH_LONG).show();
}
finally {
handler.post(runConnection);}
}
}.start();
handler = new Handler();
runConnection = new Runnable(){
@Override
public void run() {
if (threadStatus == 404) { Toast.makeText(mContext, "failed to connect to server", Toast.LENGTH_LONG).show();}
else {
mProgressDialog.dismiss();
showOnScreen();}
}
};
}