Skip to content
pyricau edited this page May 25, 2012 · 6 revisions

Since AndroidAnnotations 1.0

@Extra

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.

The extra key must be set in the annotation parameter, ie @Extra("someExtraKey").

The field must not be private. The extra can be of any type.

Usage example:

@EActivity
public class MyActivity extends Activity {

  @Extra("my_string_extra")
  String myMessage;
	
  @Extra("my_date_extra")
  Date myDateExtraWithDefaultValue = new Date();

}

Handling onNewIntent()

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().

public class MyActivity extends Activity {

    @Extra("my_string_extra")
    String myMessage;

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

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally