[android-developers] Can't properly stop a thread
In my application I am connecting to a server and downloading some
things. Not much but the connection it self takes a while. Off course
this is done in a thread (class that implements runnable). If some
error occurs, the thread sends a message to the UI using a Handler and
the UI displays an dialog window.
My problem is that I can't stop the thread in the UI properly. For
example if during the connection I would press the 'home' button on
the phone, after some seconds I get an error saying that my
application couldn't create a dialog window (because it is not running
anymore). That means that my thread was not stopped and kept on
working until an error (i.e. timeout) occurred and tried to send a
massege to the UI by a handler.
to Stop the thread I have a function that I found:
public synchronized Thread stopThread(Thread thr){
if(thr != null){
Thread temp = thr;
thr = null;
temp.interrupt();
}
return thr;
}
And I use it like:
@Override
public void onDestroy()
{
super.onDestroy();
senderTh= stopThread(senderTh);
finish();
}
Why this doesn't stop my Thread? How can I do it from the UI?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home