AndroidAnnotation
目录(?)[+]
Extras ExtraHandling onNewIntent 本文档的简单示例下载
Extras
Since AndroidAnnotations1.0
@Extra
The@Extra
annotation indicates that an activityfieldshould be injected with the correspondingExtra from theIntentthat was used to start the activity.@Extra
注解表明activity字段由启动activity传入的Intent所附带的Extra 注入。
Usage example:用法:
@EActivitypublic classMyActivityextends Activity {@Extra("myStringExtra")String myMessage;@Extra("myDateExtra")Date myDateExtraWithDefaultValue = new Date();}
Since AndroidAnnotations2.6
If you do not provide any value for the@Extra
annotation, the name of the field will be used.假如没有提供任何参数给@Extra
注解,将使用字段名作为参数。
@EActivitypublic classMyActivityextends Activity {// The name of the extra will be "myMessage"@ExtraString myMessage;}
HandlingonNewIntent()
Since AndroidAnnotations2.6
AndroidAnnotations overridessetIntent()
, and automatically reinjects the extras based on the givenIntent
when you callsetIntent()
.AndroidAnnotations重写了setIntent()
,当你调用setIntent()
的时候,将自动重新注入基于Intent
的extras。
This allows you to automatically reinject the extras by callingsetIntent()
fromonNewIntent()
.在onNewIntent()
中调用setIntent()
就会自动重新注入extras。
@EActivitypublic classMyActivityextends Activity {@Extra("myStringExtra")String myMessage;@OverrideprotectedvoidonNewIntent(Intent intent) {setIntent(intent);}}
本文档的简单示例下载
如果觉得《AndroidAnnotations——Injecting Extras注入Extras》对你有帮助,请点赞、收藏,并留下你的观点哦!