Android Annotations (1)

Source: Internet
Author: User

    • Characteristics:

Android Annotations is an open-source framework for accelerating the development of Android applications, allowing you to focus on the implementation of functionality, simplifying code, and improving maintainability.

Characteristics:
    • Dependency Injection : Inject views, extras, system services, resources, ...
    • Simplified threading Model : Annotate your methods So, they execute on the UI thread or on a background thread.
    • Event Bindings : Annotate methods to handle events on views, No more ugly anonymouslistener classes!
    • REST Client : Create a Client interface, Androidannotations generates the implementation.
    • Androidannotations provide those good things and even more for less than 50kb, without any runtimeperf impact!
@EActivity (r.layout.translate)//sets content view to R.layout.translatepublic 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);    }     // [...]}

  


How to use some common annotations:
@AfterInject defined methods are executed after the constructor method of the class is executed
@AfterTextChange defined method executes after the text property of the TextView and its subclasses is changed
@AfterViews defined methods are executed after Setcontentview
@Background defined methods are executed in the background thread
@BeforeTextChange defined methods are executed before the Text property of the TextView and its subclasses is changed
@Click Define Click Listeners
@EActivity enable annotations in activity
@EProvider enable annotations in ContentProvider
@EReceive enable annotations in Broadcastreceiver
@EService enable annotations in the service
@EView enable annotations in a child class of a custom view
@Fullscreen fullscreen
@NoTitle No title bar

Mastering these gaze is very helpful in reading the code developed with this third-party code, and has a better understanding of the anti-compilation of APK files developed with this code.

Android Annotations (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.