Skip to content
Pierre-Yves Ricau edited this page Feb 2, 2012 · 5 revisions

Overview

AndroidAnnotations works in a very simple way. It automatically adds an extra compilation step that generates source code, using the standard Java Annotation Processing Tool.

What source code ? For each enhanced class, for example each @EActivity annotated activity, a subclass of this activity is generated, with the same name plus an underscore appended at the end.

For instance, the following class:

package com.some.company;
@EActivity
public class MyActivity extends Activity {
  // ...
}

Will generate the following subclass, in the same package but in another source folder:

package com.some.company;
public final class MyActivity_ extends MyActivity {
  // ...
}

This subclass adds behavior to your activity by overriding some methods (for instance onCreate()), yet delegating the calls to super.

That is the reason why you must add _ to your activity names in AndroidManifest.xml:

<activity android:name=".MyListActivity_" />

Starting an annotated activity

In Android, you usually start an activity this way:

startActivity(this, MyListActivity.class);

However, with AndroidAnnotations, the real activity that must be started is MyListActivity_:

startActivity(this, MyListActivity_.class);

Since AndroidAnnotations 2.4

We provide static helpers to let you start the generated activities:

// Starting the activity
MyListActivity_.intent(context).start();

// Building an intent from the activity
Intent intent = MyListActivity_.intent(context).build();

// You can provide flags
MyListActivity_.intent(context).flags(FLAG_ACTIVITY_CLEAR_TOP).start();

// You can even provide extras defined with @Extra in the activity
MyListActivity_.intent(context).myDateExtra(someDate).start();

Is there any performance impact?

The short answer is no. More on this subject in the FAQ.

Now that you get the basics, let's see how to enhance Activities.

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally