Android development tutorial-Android Application Structure Analysis

Source: Internet
Author: User
Tags time and date

Android development tutorial-Android Application Structure Analysis
1. Create a HelloWorld project:

1. Open Eclipse and click "File"-> "New"-> "Project"-Android Application Project "":

 

In the pop-up "New Android Application" form, enter the corresponding Application name, project name, and package name, and select the corresponding SDK version and Application topic:

Select the project storage location and click "next" to create the project:

The created Project:

Right-click the created Project and choose "Run As"> "Android Application" from the shortcut menu to Run the created Project:

Running result:

II. Application directory structure analysis:

1. application directory structure:

2. Description of each part:

Activity file: Double-click "MainActivity. java" in the directory to view the MainActivity code:

 1 package android.basic.helloandroid; 2  3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.view.Menu; 6  7 public class MainActivity extends Activity { 8  9     @Override10     protected void onCreate(Bundle savedInstanceState) {11         super.onCreate(savedInstanceState);12         setContentView(R.layout.activity_main);13     }14 15     @Override16     public boolean onCreateOptionsMenu(Menu menu) {17         // Inflate the menu; this adds items to the action bar if it is present.18         getMenuInflater().inflate(R.menu.activity_main, menu);19         return true;20     }21 22 }

From the code, we can see that MainActivity inherits from the Activity class. Activity is the view part of Android and is responsible for processing interface display. In MainActivity, The onCreate method and onCreateOptionsMenu method of the parent class are overwritten. In the onCreate method of the override, The setContentView (R. layout. activity_main) set the view to be displayed for MainActivity. layout. activity_main: views are searched and loaded by the R class (like mvc, Activity is equivalent to Controller and layout is equivalent to a specific page ).

R file: setContentView (R. layout. in the activity_main) method, we use R. layout. activity_main specifies the view to be displayed. In the application directory structure, you can see that the R file is located under the gen directory. Double-click to display the Code:

 1 /* AUTO-GENERATED FILE.  DO NOT MODIFY. 2  * 3  * This class was automatically generated by the 4  * aapt tool from the resource data it found.  It 5  * should not be modified by hand. 6  */ 7  8 package android.basic.helloandroid; 9 10 public final class R {11     public static final class attr {12     }13     public static final class drawable {14         public static final int ic_launcher=0x7f020000;15     }16     public static final class id {17         public static final int menu_settings=0x7f070000;18     }19     public static final class layout {20         public static final int activity_main=0x7f030000;21     }22     public static final class menu {23         public static final int activity_main=0x7f060000;24     }25     public static final class string {26         public static final int app_name=0x7f040000;27         public static final int hello_world=0x7f040001;28         public static final int menu_settings=0x7f040002;29     }30     public static final class style {31         /** 32         Base application theme, dependent on API level. This theme is replaced33         by AppBaseTheme from res/values-vXX/styles.xml on newer devices.34     35 36             Theme customizations available in newer API levels can go in37             res/values-vXX/styles.xml, while customizations related to38             backward-compatibility can go here.39         40 41         Base application theme for API 11+. This theme completely replaces42         AppBaseTheme from res/values/styles.xml on API 11+ devices.43     44  API 11 theme customizations can go here. 45 46         Base application theme for API 14+. This theme completely replaces47         AppBaseTheme from BOTH res/values/styles.xml and48         res/values-v11/styles.xml on API 14+ devices.49     50  API 14 theme customizations can go here. 51          */52         public static final int AppBaseTheme=0x7f050000;53         /**  Application theme. 54  All customizations that are NOT specific to a particular API-level can go here. 55          */56         public static final int AppTheme=0x7f050001;57     }58 }

From the code, we can see that there are many classes in the R file, and there are many variables in each class. These classes and variables are added and deleted in the control or resource file (images, sounds, etc) it is automatically maintained by the development tool for us to call various resources of the application. In the comment in the first sentence of the Code, it also describes "AUTO-generated file. do not modify ".

Layout file: res/layout/activity_main.xml-layout file. Double-click activity_main.xml to enter the visual editing interface. You can select the corresponding control as needed:

You can also click the red box to enter the text editing interface to directly write the code of the corresponding control (the code file shows that the layout is composed of a relative layout and a text box ):

AndroidManifest file: The last and fourth AndroidManifest file in the application directory. xml file, which is the configuration file package of the application included in each android application, it describes the components, implemented functions, data that can be processed, and resources to be requested to the system. the conig file can also be edited by a visual editor or Text Editor:

Android. jar file: An Overview of common internal package functions of Android. jar, as shown in:

We can see that Android. jar contains many packages. The common functions of the packages are as follows:

Android. app ----------- provides high-level program models and basic runtime Environments
Android. content ------- contains various classes for accessing and publishing device data
Android. database ------ browse and operate databases through content providers
Android. graphics ------- underlying graphics library, including canvas, Color Filtering, vertices, and rectangles, which can be directly drawn to the screen.
Android. location ------- class for locating and Related Services
Android. media --------- provides media interfaces for managing multiple types of audio and video.
Android.net ------------ provides classes to help network access, exceeding the normal java.net. * interface
Android. OS ------------- provides system services, message transmission, and IPC Mechanisms.
Android. opengl -------- provides OpenGL tools
Android. provider ------- provides a class to access the content provider of Android
Android. telephony ----- provides API Interaction Related to dialing
Android. view ----------- provides the basic user interface framework
Android. util ------------ involves tools, such as time and date operations.
Android. webkit --------- default browser operation interface
Android. widget --------- contains various UI elements (mostly visible) used on the application Screen

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.