Overview of the directory structure of the HelloWorld program
We can see in the folder, the directory of the HelloWorld program mainly includes: Src folder, gen folder, Android folder, assets, res folder, Androidmanifest.xml, Default.properties. Expand the HelloWorld project on the left side of Eclipse to see a directory structure like this:
The following sections describe the above levels of directory structure.
1.src folder
As the name implies (SRC, source code) The folder is put into the source code of the project. Opening the Helloworld.java file will see the following code:
Java code
- package helloworld.test;
- import android.app.Activity;
- import android.os.Bundle;
- publicclass HelloWorld extends Activity {
- /** called when the activity is first created. */
- @Override
- publicvoid OnCreate (Bundle Savedinstancestate) {
- super . OnCreate (savedinstancestate );
- Setcontentview (r.layout.main);
- }
- }
You know: We created a simple HelloWorld project, and the system generated a Helloworld.java file for us. He imported two classes of android.app.Activity and Android.os.bundle,helloworld classes that inherit from activity and override the OnCreate method.
The following instructions are for people who have not learned Java or have a weak Java base
@Override
When overriding the oncreate of a parent class, adding a @override system in front of the method can help you check the correctness of the method. For example, Publicvoid onCreate (bundle savedinstancestate) {...} This notation is correct if you write Publicvoid onCreate (bundle savedinstancestate) {...} so the compiler returns the following error--the method OnCreate (Bundle) of type HelloWorld must override or implement a Supertype method to ensure that you correctly rewrite O Ncreate method. (because oncreate should be oncreate)
If you do not add @override, the compiler will not detect errors, but will assume that you have defined a new method OnCreate.
Android.app.Activity class: Because almost all activities (activities) interact with the user, the activity class focuses on creating Windows, and you can use the method Setcontentview (View) to put your own UI inside. However, activities are usually presented to the user in full-screen mode, or in a floating window or embedded in another activity. There are two methods that are implemented by almost all activity subclasses:
(1) onCreate (Bundle): Initialize your activities (activity), such as the completion of some drawing. Most importantly, in this method you will typically call the Setcontentview (int) method with layout resources (Resource) to define your UI, and use the Findviewbyid (int) Retrieve widgets (widgets) that you need to interact with programmatically in your UI. Setcontentview specifies which file to specify the layout (main.xml), the interface can be displayed, and then we do the operation, our operation will be wrapped as an intention, and then this intention to the relevant activity to be processed.
(2) OnPause (): Deal with what you have to do when you leave your activity. Most importantly, all changes made by the user should be committed here (usually contentprovider save the data).
Android.os.Bundle class: Maps various types of packaging (parcelable) from string values (bundle words are the meaning of bundles, all of which are well understood and remembered). If the class provides a public method--public Boolean Containkey (String key), returns False if the given key is contained in the bundle's mapping to return true. This class implements the Parceable and cloneable interfaces, so it has the characteristics of both.
2.gen folder
There is a R.java file under the folder, R.java is generated automatically when the project is built, the file is read-only and cannot be changed. The R.java file defines a class--r,r class that contains many static classes, and the name of the static class corresponds to a name in Res, which is the R class that defines the index of all resources for the project. See our HelloWorld project is not so, such as:
Through R.java we can quickly find the resources we need, in addition Yi will also check the R.java list of resources are used, the unused resources will not be compiled Yi into the software, this can reduce the use of mobile phone space occupied.
3.Android folder
The folder contains the Android.jar file, a Java archive that contains all of the Android SDK libraries (such as views, Controls) and APIs required to build the application. Bind your application to the Android SDK and Android Emulator via Android.jar, which allows you to use all of your Android libraries and packages and enable your application to debug in the right environment. For example, in the Helloworld.java source file above:
- Import android.app.Activity;
- Import Android.os.Bundle;
Here are two lines of code that import packages from Android.jar.
4.assets
Contains files such as MP3, video classes that the application needs to use.
5.res folder
The resource directory that contains the resource files in your project and will be compiled into the application. When you add a resource to this directory, it is automatically recorded by R.java. Create a new project, the Res directory will have three subdirectories: Drawabel, layout, values.
DRAWABEL-?DPI: Contains some icon files that your application can use (*.png, *.jpg)
Layout: The interface layout file (main.xml) is similar to the HTML in the Web application, and the Main.xml file that has not been modified is as follows (HelloWorld has not been modified):
xml/html Code
- <? xmlversion xmlversion = "1.0" encoding = "Utf-8" ?>
- < linearlayoutxmlns:android linearlayoutxmlns:android = "Http://schemas.android.com/apk/res/android"
- android:orientation = "Vertical"
- Android:layout_width = "Fill_parent"
- Android:layout_height = "Fill_parent"
- >
- < TextView
- Android:layout_width = "Fill_parent"
- Android:layout_height = "Wrap_content"
- Android:text = "@string/hello"
- />
- </ LinearLayout >
Values: All the text that needs to be displayed on the software. You can store multiple *.xml files, and you can store different types of data. such as Arrays.xml, Colors.xml, Dimens.xml, Styles.xml
6.androidmanifest.xml
The total configuration file for the project, documenting the various components used in the application. This file lists the features that the application provides, in which you can specify the services that the application uses (such as telephone service, Internet service, SMS service, GPS service, and so on). In addition, when you add a new activity, you need to configure it in this file, only after the configuration, you can call this activity. Androidmanifest.xml will contain the following settings: Application permissions, activities, intent filters, and so on.
If you were born or learned like me, you would find that Androidmanifest.xml is similar to the Web. config file and can be interpreted in the same way as the Web. config file.
If you are not, you can understand--well known as XML is a data interchange format, Androidmanifest.xml is used to store some data, but this data when the configuration data about the Android project.
The androidmanifest.xml of the HelloWorld project are as follows:
xml/html Code
- <? xmlversion xmlversion = "1.0" encoding = "Utf-8" ?>
- < manifestxmlns:android manifestxmlns:android = "Http://schemas.android.com/apk/res/android"
- Package = "Helloworld.test"
- Android:versioncode = "1"
- Android:versionname = "1.0" >
- Applicationandroid:icon = "@drawable/icon" Android : Label = "@string/app_name" >
- < Activityandroid:name Activityandroid:name = ". HelloWorld "
- Android:label = "@string/app_name" >
- < Intent-filter >
- < Actionandroid:name Actionandroid:name = "Android.intent.action.MAIN" />
- < Categoryandroid:name Categoryandroid:name = "Android.intent.category.LAUNCHER" />
- </ Intent-filter >
- </ Activity >
- </ Application >
- </ Manifest >
As far as Androidmanifest.xml is now, the articles later in this series will be described in detail separately.
7.default.properties
Document the environmental information required in the project, such as the Android version. HelloWorld's Default.properties file code is shown below, and the comments in the code have explained Default.properties clearly:
# This file was automatically generated by Android Tools.
# do not modify the This file--YOUR changes would be erased!
#
# This file must being checked in Version Control systems.
#
# to customize properties used by the Ant build system use,
# "Build.properties", and override values to adapt the script to your
# Project Structure.
# indicates whether an APK should being generated for each DENSITY.
SPLIT.DENSITY=FALSE
# Project target.
When we do Android development, we will find that most of the directory structure of Android programs, that is, mainly including Src folder, Gen folder, Android folder, assets, res folder, Androidmanifest.xml, Default.properties and other directories, directory structure with the above-mentioned similar.
Reprint Address: http://mobile.51cto.com/aprogram-395268_1.htm