Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

IgnoredWhenDetached

Csaba Kozák edited this page Mar 16, 2016 · 4 revisions

@IgnoreWhenDetached

Since AndroidAnnotations 3.1 until AndroidAnnotations 3.3.2

When used standalone in an @EFragment or in conjunction with the @UiThread or @Background annotations, the annotated method will be wrapped in an 'if attached' block such that no code will be executed if the @EFragment is no longer bound to its parent activity.

Should be used on method that must meet the following criteria:

  1. Can only be used in conjunction with classes annotated with @EFragment
  2. The annotated method must return void and may contain parameters.

Usage example:

@EFragment
public class LoaderFragment extends Fragment {

    [...]

    @UiThread
    @IgnoredWhenDetached
    void killActivity() {
        getActivity().finish();
    }

    @IgnoredWhenDetached
    void updateTitle(String title) {
        getActivity().setTitle(title);
    }
}

@IgnoreWhen

Since AndroidAnnotations 4.0.0

When used standalone in an @EFragment or in conjunction with the @UiThread or @Background annotations, the annotated method will be wrapped in an 'if attached' block such that no code will be executed if the @EFragment is no longer bound to its parent activity or the @EFragment views are destroyed

Should be used on method that must meet the following criteria:

  1. Can only be used in conjunction with classes annotated with @EFragment
  2. The annotated method must return void and may contain parameters.

Usage example:

@EFragment
public class LoaderFragment extends Fragment {

    [...]

    @UiThread
    @IgnoreWhen(IgnoreWhen.State.DETACHED)
    void killActivity() {
        getActivity().finish();
    }

    @IgnoreWhen(IgnoreWhen.State.VIEW_DESTROYED)
    void setViewBackground(int resid) {
        view.setBackgroundResource(resid);
    }
}

State

Since AndroidAnnotations 4.0.0

AndroidAnnotations currently support two states for ignoring execution:

  • DETACHED: Skip execution if the @EFragment is no longer bound to its parent activity.
  • VIEW_DESTROYED: Skip execution if the @EFragment views are destroyed.

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally