After injection - PerfectCarl/androidannotations GitHub Wiki
Since AndroidAnnotations 2.4
Executing code after dependency injection
If you need to execute code at build time, after dependency injection, you should use the @AfterInject
annotation on some methods.
@Enhanced
public class MyClass {
@SystemService
NotificationManager notificationManager;
@Inject
MyOtherClass dependency;
public MyClass() {
// notificationManager and dependency are null
}
@AfterInject
public void doSomethingAfterInjection() {
// notificationManager and dependency are set
}
}
Or
@EActivity
public class MyActivity extends Activity {
@SystemService
NotificationManager notificationManager;
@Inject
MyOtherClass dependency;
public MyActivity() {
// notificationManager and dependency are null
}
@AfterInject
public void doSomethingAfterInjection() {
// notificationManager and dependency are set
}
}
Please note that the view related injection hasn't occurred yet when
@AfterInject
methods are executed. You should use@AfterViews
for such needs, see [Injecting Views](Injecting Views).