Skip to content
pyricau edited this page May 26, 2012 · 49 revisions

Features

  • Simplified threading model: annotate your methods to ensure they'll be executed on the UI thread or on a background thread.
  • Event binding: annotate methods to handle events on views, no more ugly anonymous listener classes!
  • Dependency injection: inject views, extras, system services, resources, and even custom objects and let AndroidAnnotations take care of the details.
  • Rest client: define a client interface with a few annotations, and AndroidAnnotations takes care of the implementation details.
  • AndroidAnnotations provide those good things and even more for less than 50kb, without any runtime perf impact!

Next step

@EActivity(R.layout.translate) // Sets content view to R.layout.translate
public class TranslateActivity extends Activity {

    @ViewById // Injects R.id.textInput
    EditText textInput;

    @ViewById(R.id.myTextView) // Injects R.id.myTextView
    TextView result;

    @AnimationRes // Injects android.R.anim.fade_in
    Animation fadeIn;

    @Click // When R.id.doTranslate button is clicked 
    void doTranslate() {
         translateInBackground(textInput.getText().toString());
    }

    @Background // Executed in a background thread
    void translateInBackground(String textToTranslate) {
         String translatedText = callGoogleTranslate(textToTranslate);
         showResult(translatedText);
    }
   
    @UiThread // Executed in the ui thread
    void showResult(String translatedText) {
         result.setText(translatedText);
         result.startAnimation(fadeIn);
    }

    // [...]
}

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally