Android Annotations Open Source Framework Introduction

Source: Internet
Author: User
Tags modifier resource

Androidannotations is an open source framework designed to accelerate the efficiency of Android development. By using the annotation API that it opens up, you can use it almost anywhere, dramatically reducing the amount of innocuous code, allowing developers to get out and have enough time to focus on the real business logic. And by simplifying your code, it also improves the stability of your code and the cost of maintaining it later. the following androidannotations referred to as AA

There may be objections, and the performance of our mobile devices does not have sufficient memory and computational power over the backend server. When the use of a large number of annotations, will not have any adverse effects on the app, will not affect the implementation of the app performance? Here is a clear statement that AA does not bring any side effects to the app, and instead its powerful and Easy-to-use API gives you an unprecedented programming experience.

The current mainstream annotation frame has xutils, Butterknife, Dragger and roboguice, their realization principle is consistent, all are realized through the reflection mechanism. The logical code that corresponds to the annotation is executed in the runtime runtime by reflecting the field and method with annotations in the class. We all know that the reflex mechanism is performed during the runtime of the app, which can result in less efficient execution and longer execution time. The use of reflective annotations in our apps can have a significant impact on performance. But the logic of the AA's implementation is not based on this.

The principle of AA work is also very simple, it is by using JDK 1.6 introduced Java Annotation processing Tool,

Add an extra layer of automatic compilation steps in the compiler to generate code based on your source. The generated code is a direct subclass of your source, and the automatically generated class name is followed by an underscore in the parent class name. For example, using the @eactivity annotation of the myactivity, AA will automatically help you generate a class named Myactivity_ . The use of a AA annotation in the compilation of the corresponding subclass has been automatically generated, running the runtime is actually this subclass, so the use of AA does not give app performance adversely affected.

AA development environment: Right key =>properties=>java Compiler => Annotation processing => Path.

Here's a sample to learn more about this powerful framework, mainly about some common annotations.

I. Annotations of components

@EActivity This annotation is used to modify the activity, to inject the layout into the activity, or to set the page style to full screen, without title. It is convenient to use annotations with notional to achieve them. Support for other components is also fairly straightforward, such as @eservice, @EReceiver, @EProvider, @EApplication, @EApplication, @EFragment. Custom controls can also be decorated, annotated as @eview, @EViewGroup. Support is not quite comprehensive.

Ii. Annotations of resource references

With a AA, a variety of annoying findviewbyid from a go no longer return, you can simply use @viewbyid to bind the control inside the layout, if your variable name and control of the ID value consistent, even the point of the ID can be omitted. And in the note without the ID, if the compiler in the R file can not find the corresponding variable ID name, the compiler will also give you a hint, very friendly.

And if you want to refer to a resource in a member variable, just add the corresponding annotation modifier on the variable, and the ID can be omitted if the variable name and resource ID match. Support all the resource files, all of them.

If you want to get a system service, just add the @systemservice annotation to your variable.

Get the value passed in the intent, plus the @extra annotation, while the fault tolerance is good, if you do not receive the value of this key, there is no problem, you can set the default value. Then there is a strong turn failure will not cause crash, such as passing is an int value, receive the time is a string, there is no problem, just accept failure.

It's very powerful. The annotation of the modifier member variable is mainly used to solve the problem of their initialization, so that the declaration is initialized and the function can be used. There are many attributes, it is not introduced.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

Related Article

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.