My Async task is doing heavy image processing, a single Async task works successfully but if i try to execute multiple Async tasks i.e. before the first one is completed it stops working... Though it works perfectly when i debug and insert have break points to check the problem.
I only need to have break point onActivityResult
private class ProcessVideoTask extends AsyncTask<String, Void, Void> {
int goodPointsLocal;
int badPointsLocal;
String videoFileLocal;
ArrayList<Integer> xposLocal;
ArrayList<Integer> yposLocal;
ArrayList<String> markerSelectedLocal;
int windowXxLocal;
int windowYyLocal;
public ProcessVideoTask(int _goodPoints, int _badPoints,
String _videoFile, ArrayList<Integer> _xpos,
ArrayList<Integer> _ypos, ArrayList<String> _markerSelected,
int _windowXx, int _windowYy) {
// TODO Auto-generated constructor stub
goodPointsLocal = _goodPoints;
badPointsLocal = _badPoints;
videoFileLocal = _videoFile;
xposLocal = _xpos;
yposLocal = _ypos;
markerSelectedLocal = _markerSelected;
windowXxLocal = _windowXx;
windowYyLocal = _windowYy;
}
// automatically done on worker thread (separate from UI thread)
protected Void doInBackground(final String... args) {
notGotoBack = false;
String path = videoFileLocal;
ProcessVDOToImages(path);
try {//get frames from video and edit individually (heavy processing)
PutMarkersOnImages(xposLocal, yposLocal, markerSelectedLocal,
Constants.RT_EVALUATE_TRAINING, windowXxLocal,
windowYyLocal);
} catch (Exception e) {
}
mFilePathMarkers = ProcessImagestoVdo();//append audio to frames (heavy)
SetAudioWithMarkerVDO(mFilePathMarkers, videoFileLocal);
return null;
}
protected void onPostExecute(final Void unused) {
File savePathWMarker = new File(Environment
.getExternalStorageDirectory().getPath()
+ "/HumanFocus/MarkerFrame/");
File savePathWOMarker = new File(Environment
.getExternalStorageDirectory().getPath()
+ "/HumanFocus/WithoutMarkerFrame/");
if (savePathWMarker.isDirectory()) {
String[] children = savePathWMarker.list();
for (int i = 0; i < children.length; i++) {
new File(savePathWMarker, children[i]).delete();
}
}
if (savePathWOMarker.isDirectory()) {
String[] children = savePathWOMarker.list();
for (int i = 0; i < children.length; i++) {
new File(savePathWOMarker, children[i]).delete();
}
}
// change this if no Marker Video
File src = new File("");
File dst = new File("");
if (mFilePathMarkers != null) {
src = new File(mFilePathMarkers);
}
if (videoFileLocal != null) {
dst = new File(videoFileLocal);
}
try {
copyFile(src, dst);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int maxNumber = 0;
for (int i = 0; i < mCreateTraining.getAttachedFiles().size(); i++) {
String fileName = mCreateTraining.getAttachedFiles().get(i)
.getDisplayName().substring(0, 2);
if (isNumeric(fileName)) {
if (Integer.parseInt(fileName) > maxNumber)
maxNumber = Integer.parseInt(fileName);
}
}
mCreateTraining.attachFile(saveVideo(videoFileLocal,
Constants.RT_CREATE_TRAINING, goodPointsLocal,
badPointsLocal, maxNumber, videoFileLocal));
updateReportItemsList();
Toast.makeText(CreateTrainingActivity.this,
"Video Processing is Successfully Completed",
Toast.LENGTH_LONG).show();
notGotoBack = true;
}
}
To avoid over-processing i try to run it serially rather then parallel, to do it manually i made this timer.
Timer mTimer = new Timer();
mTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (processList.size() > 0) {
if (processList.get(0).getStatus() == AsyncTask.Status.FINISHED) {
processList.remove(0);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (processList.size() > 0) {
processList.get(0).execute();
}
}
}
}
}, 0, 5000);
And on activity result from the camera, Async task is created and inserted in the processList (ArrayList of AsyncTask)
if (requestCode == REQUEST_CODE_RECORD_VIDEO_ACTIVITY) {
if (data != null && data.getExtras() != null) {
Toast.makeText(CreateTrainingActivity.this,
"Video is Processing.. Please Wait ...",
Toast.LENGTH_LONG).show();
goodPoints = data.getExtras().getInt("goodPoints", 0);
badPoints = data.getExtras().getInt("badPoints", 0);
videoFile = data.getExtras().getString("data");
Xpos = data.getIntegerArrayListExtra("Xpos");
Ypos = data.getIntegerArrayListExtra("Ypos");
MarkerSelected = data.getStringArrayListExtra("MarkerSelected");
windowXx = data.getExtras().getInt("windowXx");
windowYy = data.getExtras().getInt("windowYy");
///////////////////////////////////////////////// Put tasks into queue
ProcessVideoTask mTask = new ProcessVideoTask(goodPoints,
badPoints, videoFile, Xpos, Ypos, MarkerSelected,
windowXx, windowYy);
processList.add(mTask);
if (processList.size() == 1) {
processList.get(0).execute();
}
}
This is my logcat
09-17 10:09:23.108: E/sizeee addxxxxxxxxxx(21007): 96
09-17 10:09:23.148: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.206MB for 11059216-byte allocation
09-17 10:09:23.218: I/dalvikvm-heap(21007): Grow heap (frag case) to 151.585MB for 7738604-byte allocation
09-17 10:09:23.248: I/millisUntilFinished:(21007): 1794
09-17 10:09:23.248: E/sizeee addxxxxxxxxxx(21007): 99
09-17 10:09:23.278: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.206MB for 11059216-byte allocation
09-17 10:09:23.368: E/sizeee addxxxxxxxxxx(21007): 102
09-17 10:09:23.418: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.206MB for 11059216-byte allocation
09-17 10:09:23.478: I/dalvikvm-heap(21007): Grow heap (frag case) to 151.585MB for 7738604-byte allocation
09-17 10:09:23.508: E/sizeee addxxxxxxxxxx(21007): 105
09-17 10:09:23.538: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.206MB for 11059216-byte allocation
09-17 10:09:23.608: E/sizeee addxxxxxxxxxx(21007): 108
09-17 10:09:23.668: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.206MB for 11059216-byte allocation
09-17 10:09:23.728: I/dalvikvm-heap(21007): Grow heap (frag case) to 151.585MB for 7738604-byte allocation
09-17 10:09:23.758: E/sizeee addxxxxxxxxxx(21007): 111
09-17 10:09:23.788: I/dalvikvm-heap(21007): Grow heap (frag case) to 144.207MB for 11059216-byte allocation
09-17 10:09:23.838: E/sizeee addxxxxxxxxxx(21007): 114
09-17 10:09:23.868: I/dalvikvm-heap(21007): Grow heap (frag case) to 151.586MB for 11059216-byte allocation
09-17 10:09:23.908: I/dalvikvm-heap(21007): Grow heap (frag case) to 158.966MB for 7738604-byte allocation
09-17 10:09:25.478: D/MediaRecorder(21007): Current Package Name: uk.org.humanfocus.hfi
09-17 10:09:25.488: I/Choreographer(21007): Skipped 98 frames! The application may be doing too much work on its main thread.
09-17 10:09:25.488: I/millisUntilFinished:(21007): 1791
09-17 10:09:26.498: I/millisUntilFinished:(21007): 1790
09-17 10:09:27.508: I/millisUntilFinished:(21007): 1789
09-17 10:09:28.508: I/millisUntilFinished:(21007): 1788
09-17 10:09:29.508: I/millisUntilFinished:(21007): 1787
09-17 10:09:30.508: I/millisUntilFinished:(21007): 1786
09-17 10:09:30.678: I/user interaction(21007): called
09-17 10:09:30.678: I/millisUntilFinished:(21007): 1799
09-17 10:09:31.698: I/millisUntilFinished:(21007): 1798
09-17 10:09:31.698: I/On Pause :(21007): called
09-17 10:09:32.318: I/Choreographer(21007): Skipped 30 frames! The application may be doing too much work on its main thread.