[Book note-Android game programming starts from scratch] 2. Hello, World!

Source: Internet
Author: User

2.1 create an Android Project

Application Name: Application Name (Name displayed on the mobile phone)
Project Name: Project Name
Package Name: Package Name

Min SDK Version: Minimum running Version
Create Activity: Main Activity Class Name

Minimum Required SDK: Minimum Required sdk
Target SDK: select the Target SDK
Compile SDK: Compile the SDK
Theme: topic
Holo: n. Complete; overall
Holo Dark: All black
Holo Light: holographic Light
None (default)

 

2.2 analyze the Android Project structure

1. the src directory is used to store the project source code (. java)
2. r. java file, R. the java file is the index file for all resources of the project. It is automatically generated when the project is created. java files are in read-only mode and cannot be changed. They are generally not modified. The R class contains many static classes. The names of these static classes correspond to the resource directories under the res directory one by one.
3. Android (Library) Directory: the "android. jar" file under this directory points to the Android SDK, which is all the API function libraries used to develop Android applications.
4. the assets Directory is used to store referenced external resources. The biggest difference between this directory and the res directory is that resource files under the res path will automatically generate the corresponding resource ID in the R resource file, the resources in the assets Directory are not.
5. The res directory is used to store resource files used in the project.
6. AndroidManifest is the configuration file of the current project, including the encoding format, application icon, program version number, and services used by the specified program.
7. default. properties records the environment information of the project.

 

2.3 AndroidManifest. xml and application functional components

Each Android Application must have the AndroidManifest. xml file, which defines the main functions, processing information, and executed actions of the program.

 

In the above Hierarchy Diagram, labels at the same layer are all written together according to the positional relationship, and labels at different layers are not all inclusive.
1. the outermost <manifest> defines software attributes, such as the package path, program version, and version.
2. layer 3 <application> defines application attributes and functions. For example, android: icon specifies the icon of the application, android: label defines the name of the application, and declare the function <activity> activity.
3. layer 2 is a layer that defines functional components, such as <activity> activity, <receiver ER> intent and broadcast receipt, <service> service, and <provider> attribute (content) provider, must be defined in <application>, so the <activity> activity class and activity class name are defined here.
4. <intent-filter> its function is like a filter.
5. <action> in layer 5th defines the type of intent action. <category> is the intent attribute. The value here is android. intent. category. LAUNCHER indicates that the activity is displayed on the screen when the application is started; only one intent activity can be started.

<Activity>-Activity)
An activity in Android is a user interface. For example, the dialing interface and address book interface are all activities. There can be one or more activities in the application, but if a new activity is created, it must be declared in AndroidManifest. xml.

<Receiver ER>-Intent (Intent) and Broadcast Receiver (Broadcast receiver)
The intent is to describe the action mechanism. Almost all Android phones have an intent stage. For example, there is an Intent (Intent) to send a message. In this case, if the application needs to send a message, call this Intent.
Since there is an intent, and of course an activity needs to be registered in the application to process the intent, the receiving intent can be called the Broadcast Receiver (Broadcast Receiver). For example, for example, when a mobile phone is started, a system will send a "system startup" intention, as long as the activity is registered in the application to accept this intention, the app can be automatically started when the mobile phone starts. Because there are many intentions in Android, you can specify the action to receive the intent in <intent-filter> for targeted reception. <action>, therefore, <intent-filter> is used as an intent filter.

<Service>-service
Simply put, it is the task that the application runs in the background. It does not need to display the interface or interact with the user, but needs to run in the background for a long time. For example, the music player in the Android system, when you select a song for playing, the real-time user puts the player application in the background, and then opens other programs, the music will also play as usual, then the player program must have added the service function.

<Provider>-Content Provider (Content provider)
Applications with the content provider function perform actions to allow users to save their information or files. For example, the Android mobile phone contact program provides a content provider, any application that uses the contact information can share all the information of the content provider, such as the contact name, phone number, and address.

In the AndroidManifest. xml file, apart from the functional components described above, Android has permissions to perform some key operations and access operations. If an application needs to save some data to the mobile phone's SDCard, you need to set the permission to add the SD card to AndroidManifest. xml. The syntax is <uses-permission>.

 

 

It's too simple. It can be Baidu, just a bit

 

2.5 explanation of the first Android source code

 @Override      

 

2.6 Activity Lifecycle

Lifecycle of a single Activity

1. onCreate: called when an Activity is created for the first time. Generally, a view is created here, layout information is initialized, data is bound to the list, and listeners are set. If the Activity is created for the first time, this method will call onStart (); if the Activity is stopped and re-displayed, onRestart () will be called ().
2. onStart: called when the Activity is visible to the user, and then called onResume ().
3. onRestart: when the Activity is stopped and re-displayed, it is called and onStart () is called ().
4. onResume: called when the user can perform operations on the interface.
5. onPause: This method is called when the system starts another Activity (before other activities are displayed). It is used to stop animation and other tasks that occupy CPU resources. So here we should submit and save the persistent data, which can be read in the onResume () method.
6. onStop: this API is called when another Activity is restored and the current Activity is overwritten, causing it to be invisible to users. This function is called when a new Activity is started, other activities are switched to the foreground, and the current Activity is destroyed. OnRestart () is called when the Activity returns to the foreground and interacts with the user. If the Activity exits, onDestory () is called ().
7. onDestory: The last method called before the current Activity is destroyed, call upon Process Termination (call the Finish method for the Activity directly or the system temporarily destroys the instance of the Activity to save space ).

 


An Android application can have multiple activities.

When opening another Activity and manually disabling the previous Activity, the life flow of the two activities (in an Activity, you only need to call the finish () function to exit the current Activity)

How Android OS manages Activity

 

2.7 FAQs about Android Development

Differences between Android SDK and Google APIs for Emulator Creation

Import an Android project to Eclipse

 

Display common View windows in the Android development environment in Eclipse

 

Use the print Statement (Log) in Eclipse to debug the Android Program

 

 

Run the Android project on a real machine in Eclipse

 

Simulator horizontal/vertical screen Switching

 

Package Android Projects

 

 

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.