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?