Skip to content

Commit

Permalink
Clear next auto tasks in BaseBackgroundTask on error result
Browse files Browse the repository at this point in the history
  • Loading branch information
pgp committed Mar 8, 2020
1 parent cae1d97 commit 3c4dff2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
minSdkVersion 19
targetSdkVersion 28
multiDexEnabled true
versionCode 152200304
versionName "1.5.2"
versionCode 153200308
versionName "1.5.3"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -pthread -frtti -fexceptions"
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/it/pgp/xfiles/service/BaseBackgroundTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import android.view.WindowManager;

import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.concurrent.ConcurrentLinkedDeque;

import it.pgp.xfiles.enums.FileOpsErrorCodes;
import it.pgp.xfiles.enums.ForegroundServiceType;
Expand All @@ -32,7 +32,7 @@ public abstract class BaseBackgroundTask extends AsyncTask<Object,Integer,Object

public Serializable params; // to be down-casted in subclasses

public static final Deque<Runnable> nextAutoTasks = new ArrayDeque<>();
public static final Deque<Runnable> nextAutoTasks = new ConcurrentLinkedDeque<>();

public BaseBackgroundTask(Serializable params) {
this.params = params;
Expand Down Expand Up @@ -115,8 +115,14 @@ protected void onPostExecute(Object o) {
ProgressIndicator.release();

if(!nextAutoTasks.isEmpty()) {
Log.d(getClass().getName(),"Starting next auto task...");
new Thread(nextAutoTasks.pop()).start();
if(result == null || result == FileOpsErrorCodes.OK) {
Log.d(getClass().getName(),"Starting next auto task...");
new Thread(nextAutoTasks.pop()).start();
}
else {
Log.d(getClass().getName(),"Current task failed, clearing next auto tasks...");
nextAutoTasks.clear();
}
}
}

Expand Down

0 comments on commit 3c4dff2

Please sign in to comment.