@AfterXXX call order

Kay-Uwe Janssen edited this page Oct 9, 2016 · 2 revisions

10/12/2016 The 4.2.0 release is out !

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally

Calls for method with the same @AfterXXX annotation

The calling order of methods with the same annotation within a class cannot be guaranteed and you should NOT rely on it. If you want multiple methods be called in an ensured order, you should create one method that is annotated and use that to call the other methods in their desired order. If you have to deal with parent/child classes you could try this.

Example

@AfterInject
protected void callInOrder() {
    methodA();
    methodB();
    methodC();
}

private void methodA() {
    // your code
}

private void methodB() {
    // your code
}

private void methodC() {
    // your code
}

Initial calls (after creation)

  1. @AfterExtras
  2. @AfterInject
  3. @AfterViews

Note: When @AfterExtras annotated methods are called, all injections that are not related to views are done. Therefore it is safe to use fields that are annotated with e.g. @Bean. The views are only available when the @AfterViews annotated methods get called.

Subsequent calls

  • @AfterExtras methods get called every time a new Intent reaches the Activity.
  • @AfterViews will be called everytime setContentView() is called. (Activity only)