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.
Kay-Uwe Janssen edited this page Oct 9, 2016
·
17 revisions
Since AndroidAnnotations 1.0
@Extra
The @Extra annotation indicates that an activity field should be injected with the corresponding Extra from the Intent that was used to start the activity.
If you do not provide any value for the @Extra annotation, the name of the field will be used.
@EActivitypublicclassMyActivityextendsActivity {
// The name of the extra will be "myMessage"@ExtraStringmyMessage;
}
Method based injection
Since AndroidAnnotations 4.0.0
@EActivitypublicclassMyActivityextendsActivity {
@Extra("myStringExtra")
voidsetOneExtra(StringmyMessage){
// do something with myMessage
}
voidsetMultipleExtrass(@ExtraStringmyMessage, @Extra("myDateExtra") DatemyDateExtraWithDefaultValue){
// do something with myMessage and myDateExtraWithDefaultValue
}
}
Note that you can use the intent builder to pass extra values.
MyActivity_.intent().myMessage("hello").start() ;
Handling onNewIntent()
Since AndroidAnnotations 2.6
AndroidAnnotations overrides setIntent(), and automatically reinjects the extras based on the given Intent when you call setIntent().
This allows you to automatically reinject the extras by calling setIntent() from onNewIntent().
When a method annotated with @AfterExtras is present in the activity, we override the onNewIntent() method to call setIntent().
Since AndroidAnnotations 4.0.0
WARNING: Starting with Android Annotations 4.0.0 we no longer override onNewIntent() and you have to override it by yourself if needed.
Executing code after extras injection
Since AndroidAnnotations 3.1
If you need to execute code after extras injection, you should use the @AfterExtras annotation on some methods.
@EActivitypublicclassMyClass {
@ExtraStringsomeExtra;
@ExtraintanotherExtra;
@AfterExtraspublicvoiddoSomethingAfterExtrasInjection() {
// someExtra and anotherExtra are set to the value contained in the incoming intent// if an intent does not contain one of the extra values the field remains unchanged
}
}
Warning
If the parent and child classes have @AfterViews, @AfterInject or @AfterExtras annotated methods with the same name, the generated code will be buggy. See issue #591 for more details.
Also, while there is a guaranteed order about when we call @AfterViews, -Inject or -Extras annotated methods, there is no guaranteed order for calling each of the methods with the same @AfterXXX annotation (see issue #810).
Details about when the methods with one of those annotations are called you can find here.