Android Development: Detailed program directory structure

Source: Internet
Author: User
Tags config static class

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. Expanding the HelloWorld project on the left side of Eclipse, you can see the directory structure of the following figure:





 


below is a section that describes the level of directory structure above.


1.src Folder


name (SRC, source code) The folder is 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 ' is a-created. * * @Override publicvoid OnC   Reate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);   Setcontentview (R.layout.main); }   }


Can know: we create a simple HelloWorld project, the system for us to generate a Helloworld.java file. He imported two classes Android.app.Activity and Android.os.bundle,helloworld classes to inherit from the activity and rewrite the OnCreate method.


Below is a description of people who have not learned Java or Java Foundation weakness


@Override


When overriding the OnCreate of a parent class, adding the @override system before the method can help you check the correctness of the method. For example, Publicvoid onCreate (Bundle savedinstancestate) {...} This is the correct notation if you write Publicvoid onCreate (Bundle savedinstancestate) {...} This 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)


and if you do not add @override, the compiler will not detect the error, but will think 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 to put your UI inside. However, the activity is usually displayed to the user in Full-screen mode, or it can be in a floating window or embedded in another activity. There are two methods that are implemented by almost all activity subclasses:


(1) onCreate (Bundle): Initializes your activity, such as completing some drawing of the graph. Most importantly, in this method you will typically use the layout resource (layout resource) to invoke the Setcontentview (int) method to define your UI, and with Findviewbyid (int) Retrieve widgets in your UI that you need to programmatically interact with (widgets). SETCONTENTVIEW Specifies which file specifies the layout (main.xml), the interface can be displayed, and then we do the operation, and our operations are packaged as an intention, and then the intention is to process the activity that should be related.


(2) OnPause (): Deal with what to do when you leave your activity.   Most importantly, all changes that the user makes should be submitted here (usually contentprovider save the data). Android.os.Bundle class: Maps various types of parcelable (bundle words are bundles, all of which are well understood and memorized) from string values. If the class provides a public method--public Boolean Containkey (String key), False is returned if the given key contains a return true in bundle mappings. 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 this 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, that is, the R class defines the index of all resources for the project. See our HelloWorld project is not so, the following figure:


 


By R.java we can quickly find the resources we need, and the compiler will also check whether the resources in the R.java list are being used, and the unused resources will not be compiled into the software, which will reduce the space used in the mobile phone.


don't go away, the next page continues to introduce you to the program directory structure


3.Android Folder


This folder contains Android.jar files, a Java archive containing all the Android SDK libraries (views, Controls) and APIs needed to build your application. By Android.jar your application to the Android SDK and Android emulator, this allows you to use all of the Android libraries and packages, and make your applications debug in the right environment.   For example, the above Helloworld.java source file: Import android.app.Activity; Import Android.os.Bundle;


here two lines of code are importing packages from Android.jar.


4.assets


contains files such as MP3 and video classes that the application system needs to use.


5.res Folder


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 logged by R.java. To create a new project, there will be three subdirectories in the Res directory: Drawabel, layout, values.


drawabel-?dpi: Contains some icon files (*.png, *.jpg) that your application can use


layout: interface layout files (main.xml) are similar to HTML in Web applications, and Main.xml files that have not been modified are as follows (HelloWorld are not modified):


xml/html Code


<?xmlversionxmlversion= "1.0" encoding= "Utf-8"?> <linearlayoutxmlns:androidlinearlayoutxmlns: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= "WR" Ap_content "android:text=" @string/hello "/> </LinearLayout>


values: A variety of text 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 provided by the application, in which you can specify the services that the application uses (such as telephony, Internet services, SMS services, GPS services, and so on). Also, when you add a new activity, you need to configure it in this file, and you will only be able to invoke this activity once you have configured it. Androidmanifest.xml will include the following settings: Application permissions, activities, intent filters, and so on.


If you are asp.net born or learned like me, you will find that Androidmanifest.xml is similar to Web.config file and can be similar to Web.config document understanding.


If you're not, you can understand that--it's well known that XML is a data interchange format, and Androidmanifest.xml is used to store some data, except for the configuration data about the Android project.

The androidmanifest.xml of the
HelloWorld project is as follows:


xml/html Code


<?xmlversionxmlversion= "1.0" encoding= "Utf-8"?> <manifestxmlns:androidmanifestxmlns: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: Nameactivityandroid:name= ". HelloWorld "android:label=" @string/app_name "> <intent-filter> <actionandroid:nameactionandroid:name=" Android.intent.action.MAIN "/> <categoryandroid:namecategoryandroid:name=" Android.intent.category.LAUNCHER "/> </intent-filter> </activity> </application> </manifest>


about Androidmanifest.xml now so much, the following articles in this series will be described in detail separately.


7.default.properties


records the environmental information needed in the project, such as the version of Android. HelloWorld's default.properties file code looks like this, and the comments in the code explain the Default.properties clearly:


# This file was automatically generated by Android Tools.   # don't modify this file--YOUR CHANGES would be erased!   # This file must is checked in Version control Systems. # to customize properties used by the ANT builds system use, # ' Build.properties ', and override values to adapt the S   Cript to your # project structure.   # Indicates whether an APK should is generated for each density.   Split.density=false # Project Target. Target=android-7


when we do Android development, we find that most of the Android apps have the same directory structure, which includes SRC folders, gen folders, Android folders, assets, res folders, Androidmanifest.xml, Default.properties directory structure is similar to the above.
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.