I have a check box. If I checked it then I need to upload data to server. I have written this uploading logic in a Thread class. If I uncheck the checkbox I want to cancel the uploading and so on. The problem is that while trying to use the same thread if in some situation I am getting thread state as TERMINATED (this.getState() == Thread.State.TERMINATED)
. What I need to do in this case? If thread state is new then I will call start()
method. But in this case what do I need to do?
Asked
Active
Viewed 83 times
1

Bart
- 19,692
- 7
- 68
- 77

Sunil Kumar Sahoo
- 53,011
- 55
- 178
- 243
-
1This means that the Thread finished doing its job and therefore cannot be used anymore. You need to create a new Thread. – Guillaume Polet Mar 07 '12 at 11:59
-
If you need to interact between your GUI and another thread, it is maybe worth considering using SwingWorkers instead of a Thread. SwingWorkers can be cancelled like this: http://stackoverflow.com/questions/6113944/how-cancel-the-execution-of-a-swingworker – assylias Mar 07 '12 at 11:59
-
@assylias, Swing means nothing in Android. – Mar 07 '12 at 12:28
-
As stated by @Caner, use AsyncTask instead. – Caumons Apr 21 '12 at 11:49
2 Answers
0
Simple answer: do not reuse thread. Thread pooling has its advantages on big serverside sysems, but not on mobile phone there is no advantage.
Terminated thread is dead, no action is necessary on your side anymore

Konstantin Pribluda
- 12,329
- 1
- 30
- 35
-
It's not that complex. I use threads in Android regularly. I haven't seen something worst with threads... – Mar 07 '12 at 12:30
0
Use can try to use AsyncTask
instead of thread.
http://developer.android.com/reference/android/os/AsyncTask.html

Caner
- 57,267
- 35
- 174
- 180