Thread is already running when it is already stopped
In my download manager, I auto-pause the download when the activity is
paused or stop. Any running downloads are interrupted. I know I should let
it download even in background but that is not the point here.
The thing is, on resume, the download must continue. However, I get an
exception that the thread is already running when in logcat I have a log
that I placed which clearly says thread is interrupted.
The line pointed to is of the Scheduler class which is responsible for
running the threads:
public class Scheduler extends TimerTask {
private static int index = 0;
//------------------------------------------------------------------------------
@Override
public void run() {
if(Sharable.isResumed()){ // activity is ready for interaction
with user
if(Sharable.getShouldLook()){ // and we are ready to download
while(index < Sharable.downloads.size()){
Task t = Sharable.downloads.get(index++);
Log.v("SCHEDULER", "CHECKING");
if(t.getReadiness()==true && t.getProgress() != 100){
Log.v("TASK-- ", t.toString() + " is not
running. Now starting");
if(!t.isAlive()){ // check if not already running
t.start(); // start the thread
}
break;
}
}
index = 0;
}
}
}
//------------------------------------------------------------------------------
}
t.start() is the culprit. WHY? I do not know why.
So what is in the logcat ?
08-21 15:50:54.316: V/TASKPATH(1460): /sdcard/tqa-se3ep47.mp3
08-21 15:50:54.386: V/TASK(1460): SETTING PATH
08-21 15:50:54.437: V/TASK(1460): MAKING URL
08-21 15:50:54.437: V/TASK(1460): MAKING CONNECTION
08-21 15:50:54.466: V/TASK(1460): Range:bytes=16636099-
08-21 15:50:54.466: V/TASK(1460): BYTES-WRITTEN: 16636099
08-21 15:50:54.514: V/TASK(1460): CONTENT-LENGTH: 27452333
08-21 15:50:55.326: V/TASK(1460): CONNECTED
08-21 15:50:56.886: V/TASK(1460): CODE: 206
08-21 15:50:56.886: V/TASK(1460): Partial Content
08-21 15:50:56.896: V/TASK(1460): Writing at location 16636099
.... some useless logs skipped for sake of sanity ....
08-21 15:51:00.986: V/TASK(1460): Writing at location 16763075
08-21 15:51:01.036: V/TASK(1460): 61.0
08-21 15:51:01.046: V/TASK(1460): Writing at location 16765123
08-21 15:51:01.056: V/TASK(1460): 61.0
08-21 15:51:01.196: V/TASK(1460): Writing at location 16767171
08-21 15:51:01.196: V/TASK(1460): 61.0
08-21 15:51:01.246: V/TASK(1460): Writing at location 16769219
08-21 15:51:01.246: V/TASK(1460): 61.0
08-21 15:51:01.266: V/TASK(1460): Writing at location 16771267
08-21 15:51:01.286: V/TASK(1460): 61.0
08-21 15:51:01.426: V/TASK(1460): Writing at location 16773315
08-21 15:51:01.437: V/TASK(1460): 61.0
08-21 15:51:01.486: V/TASK(1460): Writing at location 16775363
08-21 15:51:01.516: V/TASK(1460): 61.0
08-21 15:51:01.546: V/TASK(1460): Writing at location 16777411
08-21 15:51:01.546: V/TASK(1460): 61.0
08-21 15:51:01.586: V/TASK(1460): Writing at location 16779459
08-21 15:51:01.586: V/TASK(1460): 61.0
08-21 15:51:01.616: V/TASK(1460): Writing at location 16781507
08-21 15:51:01.616: V/TASK(1460): 61.0
08-21 15:51:01.676: V/TASK(1460): Writing at location 16783555
08-21 15:51:01.887: V/TASK(1460): 61.0
08-21 15:51:02.106: V/TASK(1460): INTERRUPTED
08-21 15:51:12.319: V/TASK--(1460): tqa-se3ep47.mp3 is not running. Now
starting
Well, and then the app stops working. How do I solve this ???
No comments:
Post a Comment