Home - PerfectCarl/androidannotations GitHub Wiki
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:
The ratio of time spent reading [code] versus writing is well over 10 to 1 [therefore] making it easy to read 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 50kb, without any runtime perf impact!
Next step
- Convinced? Get started!
- Curious? Read how it works
- Need proofs? See the apps already using AndroidAnnotations
- Looking for recipes? Read the cookbook
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.