mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-09 18:48:51 -06:00
BaseTask: move register/unregister to onPre/PostExecute
This commit is contained in:
@@ -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