Android Learning Note-android Application Preliminary understanding

Source: Internet
Author: User

Always feel that their technology does not have a specialty, it seems that anything will be a little, but not in depth. decided to learn the development of Android, can not say the reason, I hope that they will continue.

In fact, has already set up the development environment of Android ECLIPSE+ADT+SDK, here do not do specific introduction, personally think it is very necessary to put these 3 software installed separately,

This will have a systematic understanding of the development tools. Eclipse is an IDE that can be used for many development languages, and the SDK is a framework for Android app development with

The package used in the process and some integrated tools, ADT is a plug-in installed on eclipse, so that the Eclipse and SDK can be associated, so that developers through the eclipse of the IDE

Easy to develop for Android applications.

I use the tutorial is "the first line of code:Android", mainly to see Stormzhang recommendations, but also read the author Guo Lin in the CSDN blog, the worship of Daniel spontaneously.

After probation a PDF tutorial, I immediately decided to use it to get me started.

The main lesson today is to create the first HelloWorld Android program and a more general understanding of the overall structure of the Android program.

After creating a new Android Application project, the project directory structure is as follows:

The uses for each directory are as follows:

1, src is the java source code storage directory

2, Gen This directory is automatically generated by ADT , mainly has a R.java and Buildconfig.java files, These files can not be modified manually, the meaning of the following to carefully understand

3. Assets Directory is a file that is used when you package with the program

4, Bin does not need too much attention, the current project after the compilation of the installation package will be saved here, such as helloworld.apk

5, Libs storage for the development of the first 3 - Party jar Package

6, the Res directory sub-directory has:drawable Storage of various models to fit the picture,layout, layouts files,menu Store the menu file, Values String configuration file

7. Androidmanifest.xml the entire Android project configuration file, all four components defined in the program need to be registered in this file. Other settings are also available, followed by detailed analysis.

8, Project.Properties specifies the version of the SDK used to compile the program , in my case, is actually "target=android-14" This line of code

Operating mechanism of Android program

Android has 4 components, namely activities, services, broadcast receivers, and content providers. I am currently only exposed to this component of the activity. So let's start by documenting your current knowledge:

Providing the activity component is actually providing a subclass that inherits from the activity class, which needs to implement the OnCreate () method of the base class, which is the method that must be executed when the activity is created. Of course

I also try to rename this method (the implementation has not changed), the result is that the interface can still be presented, but the specific differences are estimated to be able to understand later in-depth study. In addition, the base class method Oncreateoptionsmenu () is used for menu creation,

It is not a point to delve into this.

In the Res/layout directory, you can create an Android XML file of layout type, in which we can add the simplest TextView control to display a string, as in the following example:

    < TextView         Android:layout_width = "Wrap_content"         android:layout_height= "Wrap_content"        android:text= "@string/hello_ World "/>
View Code

The string shown here is obtained through @string/hello_world, @string/tag_name is from res/values/ A way to get a value in Strings.xml, which is convenient because you only need to modify the Strings.xml file to

Present the app in a different language. There are two ways to read configuration items in a strings.xml like this:

1. A reference to the string can be obtained by R.string.hello_world in the code;

2. A reference to the string can be obtained through @string/hello_world in the XML.

In the OnCreate method of the activity component, the layout content is displayed through Setcontentview (r.layout.first_layout) after the creation of the layout type file.

@Override protected void onCreate (Bundle savedinstancestate) {    super. OnCreate (savedinstancestate);    Setcontentview (r.layout.first_layout);}
View Code

After using the layout type file in the OnCreate method of the replication, the last step is to register the activity in the Androidmanifest.xml file. Here's how:

    <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >                <ActivityAndroid:name=". Firstactivity "Android:label= "This is firstactivity" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>                     </Activity>    </Application>
View Code

Where the <activity> tag is the basic operation of the activity registration, where the <intent-filter> tag content is essential, I myself in the course of the experiment because I made a mistake to write the category action, The result is an error.

After the activity is properly registered in Androidmanifest.xml, one of the simplest Android apps is created, and the project is run to see the display on the device HelloWorld

Summarizing my initial understanding of the Android application, the layout is implemented by the type XML file, and the activity class implements functions such as loading layout layouts, displaying menus, and finally androidmanifest.xml

The file registers the activity to ensure that the activity components are displayed correctly on the device.

Android Learning Note-android Application Preliminary understanding

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.