Since AndroidAnnotations 1.0
@Extra
The @Extra
annotation indicates that an activity field should be injected with the correspondingExtra from the Intent that was used to start the activity. @Extra
注解表明activity字段由启动activity传入的Intent所附带的Extra 注入。
Usage example:用法:
@EActivitypublic 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.假如没有提供任何参数给 @Extra
注解,将使用字段名作为参数。
@EActivitypublic class MyActivity extends Activity { // The name of the extra will be "myMessage" @Extra String myMessage;}
Handling onNewIntent()
Since AndroidAnnotations 2.6
AndroidAnnotations overrides setIntent()
, and automatically reinjects the extras based on the given Intent
when you call setIntent()
.AndroidAnnotations重写了 setIntent()
,当你调用setIntent()
的时候,将自动重新注入基于Intent
的extras。
This allows you to automatically reinject the extras by calling setIntent()
from onNewIntent()
.在onNewIntent()
中调用 setIntent()
就会自动重新注入extras。
@EActivitypublic class MyActivity extends Activity { @Extra("myStringExtra") String myMessage; @Override protected void onNewIntent(Intent intent) { setIntent(intent); }}
本文档的简单示例下载