Androidannotations instruction manual How does-androidannotations work?

Source: Internet
Author: User

Androidannotations works very simply by using the standard Java Injection processing tool, which automatically adds an additional compilation step to generate the source code.

What is the source code? Each enhanced class, such as every activity injected with @eactivity, automatically generates an activity subclass with the class name + underscore as the class name.

For example, the following class:
Package com.some.company; @EActivitypublic class MyActivity extends Activity {  //...}

The following subclass will be generated, under the same package but in a different folder:
Package Com.some.company;public Final class Myactivity_ extends MyActivity {  //...}

This subclass adds some behavior to your activity by copying some methods, such as OnCreate ().

These are the reasons you need to add an underscore to your class name when you androidmanifest.xml life acitivty:
<activity android:name= ". Mylistactivity_ "/>


To start an activity that uses injections:

in Android, we usually start an activity in the following way:
StartActivity (this, mylistactivity.class);
However, if you use androidannotations, the activity that is actually initiated is mylistactivity_ instead of mylistactivity:
StartActivity (this, mylistactivity_.class);


Intent Builder (androidannotations 2.4 and above):
We have provided a static helper class to start the activity of compiling the build:
Starting the Activitymylistactivity_.intent (context). Start ();//Building an intent from the activityintent intent = MyL Istactivity_.intent (context). get ();//You can provide flagsmylistactivity_.intent (context). Flags (flag_activity_ Clear_top). Start ();//You can even provide extras defined with @Extra in the activitymylistactivity_.intent (context). Myda Teextra (Somedate). Start ();


in Androidannotations 2.7 and later, you can use another method of starting activity Startactivityforresult ():
Mylistactivity_.intent (context). Startforresult ();


To start a service that uses annotations:
in Android, we usually start a service in the following way:
StartService (this, myservice.class);


However, if you use Androidannotations, the service that is actually started is myservice_ instead of MyService:
StartService (this, myservice_.class);


Intent Builder (androidannotations 2.7 and later):
We provide a static help class to start the production of the service:
Starting the Servicemyservice_.intent (context). Start ();//Building an intent from the activityintent intent = MyService _.intent (context). build ();//You can provide flagsmyservice_.intent (context). Flags (Intent.flag_grant_read_uri_ PERMISSION). Start ();

Androidannotations instruction manual How does-androidannotations work?

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.