BaseTask: move register/unregister to onPre/PostExecute

This commit is contained in:
2016-04-04 05:42:27 -04:00
parent c51b1fd399
commit 0de52d4fa3
3 changed files with 18 additions and 14 deletions

View File

@@ -34,8 +34,6 @@ import org.junit.runner.RunWith;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

View File

@@ -164,6 +164,8 @@ public class HabitListLoader
currentFetchTask = null;
if(listener != null) listener.onLoadFinished();
super.onPostExecute(null);
}
};
@@ -194,6 +196,8 @@ public class HabitListLoader
{
if(listener != null)
listener.onLoadFinished();
super.onPostExecute(null);
}
}.execute();
}

View File

@@ -27,27 +27,29 @@ public abstract class BaseTask extends AsyncTask<Void, Integer, Void>
{
private static int activeTaskCount;
@Override
protected void onPreExecute()
{
super.onPreExecute();
activeTaskCount++;
}
@Override
protected void onPostExecute(Void aVoid)
{
activeTaskCount--;
super.onPostExecute(null);
}
@Override
protected final Void doInBackground(Void... params)
{
register();
doInBackground();
unregister();
return null;
}
protected abstract void doInBackground();
protected void register()
{
activeTaskCount++;
}
protected void unregister()
{
activeTaskCount--;
}
public static void waitForTasks(long timeout)
throws TimeoutException, InterruptedException
{