Android tool-annotations,-annotations

Source: Internet
Author: User

Android tool-annotations,-annotations

Currently, annotations are widely used in java to improve development efficiency. In android, it mainly helps developers process front and back-end tasks, rest services, application classes, code snippets, and so on, so that developers can focus on what really matters.

(1) how to use android annotations

For more information, see this document.


(2) Example

/*** Example of android annotations ** @ author peter_wang * @ create-time 7:40:56 * // set the layout file of the Activity @ EActivity (R. layout. activity_http_request) public class HttpRequestActivity extends Activity {// equivalent to findviewById. The default name is id name @ ViewById TextView TV _response_main; // string resource file information @ StringRes (R. string. hello_world) String mHelloWorld; // The action after oncreate is executed @ AfterViews void init () {TV _response_main. SetText (mHelloWorld);} // Click event. TV _response_main indicates the clicked View object id @ Click void TV _response_mainClicked () {getHttpData ();} // Background execution thread @ Background void getHttpData () {try {// get the HttpClient object HttpClient getClient = new DefaultHttpClient (); // get the HttpGet object HttpGet request = new HttpGet ("http: // 192.168.140.1: 8080/SimpleServer/servlet/PayServlet? Id = 1 "); // The client uses the GET method to obtain the server response HttpResponse response = getClient.exe cute (request); // determine whether the request is successful if (response. getStatusLine (). getStatusCode () = HttpStatus. SC _ OK) {// obtain the input stream InputStreamReader inStrem = new InputStreamReader (response. getEntity (). getContent (); BufferedReader br = new BufferedReader (inStrem); StringBuilder sb = new StringBuilder (); String readLine = null; while (readLine = Br. readLine ())! = Null) {sb. append (readLine);} setHttpDataUI (sb. toString (); // close the inStrem of the input stream. close () ;}else {}} catch (Exception e) {e. printStackTrace () ;}// update UI @ UiThread void setHttpDataUI (String data) {TV _response_main.setText (data);} in the thread );}}


(3) Working Principle

Android annotations originated from java annotations. You can read this article for a brief understanding of java annotations.

Java annotations contains three types: SourceCode, Class, and Runtime.

Android annotations are of the SourceCode type. Java Annotation Processing Tool (APT) is used to compile the source file (*. java) previously, through the annotation processor (AnnotationProcessor) to interpret and process the annotation in the source file, to generate some new source files, APT will also compile the new source files until no new files are generated. The newly generated source file is in the apt_generated folder.

Before Compilation

package com.some.company;@EActivitypublic class MyActivity extends Activity {  // ...}

After compilation

package com.some.company;public final class MyActivity_ extends MyActivity {  // ...}
The Activity generates a new Activity _ file. Therefore, the Activity and Application used in AndroidManifest. xml must be underlined: xxActivity _, xxApplication _.


(4) Advantages

(1) simplified development and improved efficiency. Dependencies are injected into layout, views, resources, services, and other common operations.

(2) open. The generated source file is visible.

(3) performance is not affected. Because it is not a runtime operation, new source files are generated during the compilation period, which does not affect the running speed.



What tools are used for Android development?

Android is based on linux, so it is the best in ubuntu. Of course, it is also possible under windows. However, the android kernel is based on linux and various operations are performed through the terminal, which is very powerful and more convenient than cmd. The self-developed environment is as follows:
I used to install a ubuntu Virtual Machine on windows. Most android development involves application development from the middle layer to the top layer, so it is basically java development. The table configuration is as follows:
1. Eclipse is essential for java Development and android. (Of course, the premise is to install JDK1.6 first)
2. Download the android SDK and ADT. This is a required tool for android development. It is required for adb, ddms, mksdcard, aapt, and debug.

A. After installing eclipse, use help => install new software .. Install ADT
B. Then window => preference: Set the SDK path.
If C is used for development, you can install CDT.

Now you can use AVD manager to install the api on which platform you want to use, such as android2.3.4, to create an emulator of 2.3.4 and run the simulator. You can view and develop data using tools such as adb ddms. Add the adb path to the environment variable for convenience.

Well, that's all. You can develop it after configuration. Good luck to you ~~
Reference: zhidao.baidu.com/question/301811184.html

Android development requires development tools

JDK1.6 or above
Eclipse + ADT plug-in
The file size of the andoid SDK depends on the ins from 1 GB to 7 GB.
You can use PS and other tools if the interface is beautiful.

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.