AndroidAnnotations——Injecting Extras注入Extras

Extras

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:用法:

@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.假如没有提供任何参数给 @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。

@EActivity
public class MyActivity extends Activity {

    @Extra("myStringExtra")
    String myMessage;

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
    }
}

本文档的简单示例下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值