BaseTask: move register/unregister to onPre/PostExecute

pull/77/merge
Alinson S. Xavier 10 years ago
parent c51b1fd399
commit 0de52d4fa3

@ -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;

@ -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();
}

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

Loading…
Cancel
Save