You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
When using @Background in conjunction with @UIThread annotations on an @EFragment, it's possible that many developers don't want to run the method annotated with the @UIThread annotation if the Fragment is no longer attached to the activity. I think it would be great to add an annotation (something like @IgnoredWhenDetached) with the following rules:
Must also have the @UIThread annotation
Can only be used in conjunction with @EFragment classes
Simply wraps the @UIThreadmethod call in an if block like so
if(isAdded()) {
//executable code
}
or
if(getActivity() != null) {
//executable code
}
Here is a simple example and in my application I have dozens of things similar to this
This essentially prevents the two @UIThread methods from getting a NPE if the Fragment were to have been destroyed at any point during the execution of the @Background method. While I realize this is something that can be easily guarded against by a simple null check, it makes the code much cleaner and is a very common use case in conjunction with Fragments. I would be more than happy to submit a pull request pending thoughts/comments about this. This could also be useful in conjunction with @Background on an @EFragment as well, but not a very common use case.