-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Extras
Since AndroidAnnotations 1.0
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.
Usage example:
@EActivity
public class MyActivity extends Activity {
@Extra("myStringExtra")
String myMessage;
@Extra("myDateExtra")
Date myDateExtraWithDefaultValue = new Date();
}
Since AndroidAnnotations 2.6
If you do not provide any value for the @Extra
annotation, the name of the field will be used.
@EActivity
public class MyActivity extends Activity {
// The name of the extra will be "myMessage"
@Extra
String myMessage;
}
Since AndroidAnnotations 4.0.0
@EActivity
public class MyActivity extends Activity {
@Extra("myStringExtra")
void setOneExtra(String myMessage){
// do something with myMessage
}
void setMultipleExtrass(@Extra String myMessage, @Extra("myDateExtra") Date myDateExtraWithDefaultValue){
// do something with myMessage and myDateExtraWithDefaultValue
}
}
Note that you can use the intent builder to pass extra values.
MyActivity_.intent().myMessage("hello").start() ;
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()
.
@EActivity
public class MyActivity extends Activity {
@Extra("myStringExtra")
String myMessage;
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
}
Since AndroidAnnotations 3.2
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.
Since AndroidAnnotations 3.1
If you need to execute code after extras injection, you should use the @AfterExtras
annotation on some methods.
@EActivity
public class MyClass {
@Extra
String someExtra;
@Extra
int anotherExtra;
@AfterExtras
public void doSomethingAfterExtrasInjection() {
// 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
}
}
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.
19/11/2020 The 4.8.0 release is out !
- Get started!
- Cookbook, full of recipes
- Customize annotation processing
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow
- Ask on Gitter