Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
Kay-Uwe Janssen edited this page Nov 23, 2016 · 55 revisions

Introduction

Goals

We want to facilitate the writing and the maintenance of Android applications.

We believe that simple code with clear intents is the best way to achieve those goals.

Robert C. Martin wrote in "Clean Code: A Handbook of Agile Software Craftsmanship":

The ratio of time spent reading [code] versus writing is well over 10 to 1. [...] Of course there’s no way to write code without reading it, so making it easy to read actually makes it easier to write.

While we all enjoy developing Android applications, we often wonder: Why do we always need to write the same code over and over? Why are our apps harder and harder to maintain? Context and Activity god objects, complexity of juggling with threads, hard to discover API, loads of anonymous listener classes, tons of unneeded casts... can't we improve that?

How?

Using Java annotations, developers can show their intent and let AndroidAnnotations generate the plumbing code at compile time.

Features

  • Dependency injection: inject views, extras, system services, resources, ...
  • Simplified threading model: annotate your methods so that they execute on the UI thread or on a background thread.
  • Event binding: annotate methods to handle events on views, no more ugly anonymous listener classes!
  • REST client: create a client interface, AndroidAnnotations generates the implementation.
  • No magic: As AndroidAnnotations generate subclasses at compile time, you can check the code to see how it works.
  • AndroidAnnotations provide those good things and even more for less than 150kb, without any runtime perf impact!

Next step

Code sample

Is your Android code easy to write, read, and maintain?

Look at that:

@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);
    }

    // [...]
}

The project logo is based on the Android logo, created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

Android is a trademark of Google Inc. Use of this trademark is subject to Google Permissions.

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally