Android Annotation(AA) is framework that facilitate the writing and the maintenance of Android Applications, and greatly simplifies the code. It generates subclasses at compile time, for example, the subclass of the MainActivity class would be MainActivity_. To understand how the AA works, you can have a look at the subclass of the Activity.
How to enhance Android Code with AA
I would like to discuss the common annotations that would be used in Android Development.
Add @EActivity with layout id at the top of the class to replace setContentView of the Activity Class
1 2 |
|
Add @ViewById to replace findViewById
1 2 |
|
Add @Bean to inject the activity context into class
1 2 |
|
Add @AfterView before method to do something after view injection, for example, setText, setBackground, etc..
1 2 |
|
Add @Click method with view’s id to handle OnClickListener.
1 2 |
|
That’s it. There is no need to do “findViewById” to get the view then followed by setOnClickListener.
Want to run a thread? Add @Background above the method
1 2 |
|
Initiate the Layoutinflator using @SystemService
1 2 |
|
Add EBean at the top of the CLass in order to use available annotations
1 2 |
|
Add @RootContext to inject the context into the class
1 2 |
|