Skip to content

@AfterXXX call order

dodgex edited this page Sep 23, 2014 · 1 revision

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)

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally