mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|||||||
@@ -164,6 +164,8 @@ public class HabitListLoader
|
|||||||
currentFetchTask = null;
|
currentFetchTask = null;
|
||||||
|
|
||||||
if(listener != null) listener.onLoadFinished();
|
if(listener != null) listener.onLoadFinished();
|
||||||
|
|
||||||
|
super.onPostExecute(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -194,6 +196,8 @@ public class HabitListLoader
|
|||||||
{
|
{
|
||||||
if(listener != null)
|
if(listener != null)
|
||||||
listener.onLoadFinished();
|
listener.onLoadFinished();
|
||||||
|
|
||||||
|
super.onPostExecute(null);
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,27 +27,29 @@ public abstract class BaseTask extends AsyncTask<Void, Integer, Void>
|
|||||||
{
|
{
|
||||||
private static int activeTaskCount;
|
private static int activeTaskCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute()
|
||||||
|
{
|
||||||
|
super.onPreExecute();
|
||||||
|
activeTaskCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid)
|
||||||
|
{
|
||||||
|
activeTaskCount--;
|
||||||
|
super.onPostExecute(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final Void doInBackground(Void... params)
|
protected final Void doInBackground(Void... params)
|
||||||
{
|
{
|
||||||
register();
|
|
||||||
doInBackground();
|
doInBackground();
|
||||||
unregister();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void doInBackground();
|
protected abstract void doInBackground();
|
||||||
|
|
||||||
protected void register()
|
|
||||||
{
|
|
||||||
activeTaskCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void unregister()
|
|
||||||
{
|
|
||||||
activeTaskCount--;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void waitForTasks(long timeout)
|
public static void waitForTasks(long timeout)
|
||||||
throws TimeoutException, InterruptedException
|
throws TimeoutException, InterruptedException
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user