失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > AndroidAnnotations——Injecting Extras注入Extras

AndroidAnnotations——Injecting Extras注入Extras

时间:2021-09-16 07:39:18

相关推荐

AndroidAnnotations——Injecting Extras注入Extras

AndroidAnnotation

目录(?)[+]

Extras ExtraHandling onNewIntent 本文档的简单示例下载

Extras

Since AndroidAnnotations1.0

@Extra

The@Extraannotation 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@Extraannotation, 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 givenIntentwhen 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》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。