This is not a bug but a discussion of a feature request.
TL;DR extend AA to execute methods only in certain life-cycle states
In my code I have to repeatedly check if a method annotated with @UiThread is not being called after the activity / fragment has been destroyed. Most of the time this occurs when a long running background operation returns to display its result.
@UiThread
protected void foo() {
if (!isResumed()) {
return;
}
// [...]
}
To prevent to write this check manually every time my idea was to add a parameter lifespan to the @UiThread annotation (Or whatever because I'm bad at naming things). Its values could be the following:
enum LIFESPAN {
CREATED, //valid between onCreate and onDestroy
STARTED, //valid between onStart and onStop
RESUMED //valid between onResume and onPause
};
An annotated method would look this way:
@UiThread(lifespan = RESUMED)
protected void foo() {
// [...] executed when activity / fragment is in resumed state
}
The generated class would have to override the onCreate... lifecycle methods to save the current state and query this state inside the generated methods that use the lifespan parameter.
The downside of this idea is that the parameter could only be used in activities or fragments and as a result the @UiThread annotation would not have the same features in all @E... anymore.
An alternate approach would be to create a new annotation similar to @IgnoreWhen that checks for the lifecycle states in @EActivity and @EFragment.
What is your opinion on this matter?
This is not a bug but a discussion of a feature request.
TL;DR extend AA to execute methods only in certain life-cycle states
In my code I have to repeatedly check if a method annotated with
@UiThreadis not being called after the activity / fragment has been destroyed. Most of the time this occurs when a long running background operation returns to display its result.To prevent to write this check manually every time my idea was to add a parameter
lifespanto the@UiThreadannotation (Orwhateverbecause I'm bad at naming things). Its values could be the following:An annotated method would look this way:
The generated class would have to override the onCreate... lifecycle methods to save the current state and query this state inside the generated methods that use the
lifespanparameter.The downside of this idea is that the parameter could only be used in activities or fragments and as a result the
@UiThreadannotation would not have the same features in all@E...anymore.An alternate approach would be to create a new annotation similar to
@IgnoreWhenthat checks for the lifecycle states in@EActivityand@EFragment.What is your opinion on this matter?