mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
BaseTask: move register/unregister to onPre/PostExecute
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user