More granular transient states

This commit is contained in:
M66B
2018-12-21 08:49:31 +01:00
parent 533c763457
commit 099239ca64
2 changed files with 43 additions and 14 deletions

View File

@@ -117,6 +117,12 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
this.args = null;
this.stored = null;
try {
onInit(args);
} catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
}
owner.getLifecycle().addObserver(this);
final Handler handler = new Handler();
@@ -160,11 +166,19 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
} catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
} finally {
try {
onCleanup(args);
} catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
}
onDestroyed();
}
}
}
protected void onInit(Bundle args) {
}
protected abstract T onLoad(Context context, Bundle args) throws Throwable;
protected void onLoaded(Bundle args, T data) {
@@ -172,6 +186,9 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
protected abstract void onException(Bundle args, Throwable ex);
protected void onCleanup(Bundle args) {
}
private static class Result {
Throwable ex;
Object data;