Original link: http://www.orlion.ga/387/
First, the system architecture of Android
1.
-
Linux kernel layer, this layer provides the underlying driver for Android devices
-
The system runtime layer, which provides key feature support for Android systems through a number of C + + libraries. such as the SQLite library provides database support, opengl| The El Library provides support for 3D drawings, and the WebKit Library provides support for the browser kernel. There is also the Android Runtime Library, which provides some core libraries that allow developers to develop Android apps using Java. In addition, the Android Runtime library contains the Dalvik virtual machine, which allows each Android app to run in a separate process and have its own Dalvik virtual machine instance
-
Application framework layer, which provides the APIs that are likely to be used when building apps
-
Application tier, all applications installed on the phone belong to this layer
What Android offers:
-
Four components, Android four components are active activity, service services, broadcast receiver broadcast receiver and content provider Provider. Activity is the façade of all Android apps, and everything you see in the app is in the activity. The service continues to run silently in the background, and even if the user exits the app, the services can continue to run. Broadcast receiver allows applications to receive broadcast messages, such as phone calls, text messages, and so on, and of course their own applications can send out broadcast messages. Content provider provides the possibility of sharing data between applications, such as the need to read the contacts in the system phone book, which is done through the contents provider.
-
Rich system controls, Android system provides developers with a rich system of controls, so that we can easily write a beautiful interface. Of course, if you have a high taste and are not satisfied with the control effect that comes with your system, you can also customize your own controls.
-
SQLite database, Android system also comes with this lightweight, fast computing embedded relational database, not only support standard SQL can also be operated through the Android packaged API.
-
Location positioning, Android basic built-in GPS
-
Powerful multimedia, Android provides a wealth of multimedia services, such as music, video, recording, photo, alarm, etc., which can be controlled through the code in the app.
-
Sensors, many of them have built-in sensors such as directional sensors, accelerometer sensors
Second, the first Android project HelloWorld
1. Create an Android project
file->new-> Android Application Project
And then all the way next.
2. Running the project
First create an Android emulator, click on the Eclipse toolbar Android Virtual Device Manager
Then the project right-click Run as->android application.
3, the project directory introduction:
A.SRC: Where Java code is stored
B.gen: Automatically generated content, mainly has a R.java file, any resources added anywhere in the project will generate a corresponding resource ID in it, do not modify the file
C.assets: You can store some files that are packaged with the program. In addition, if the program uses the WebView to load the local page, all pages related files are also placed in this directory
D.bin: Mainly contains some files generated automatically at compile time, which will have a current project compiled APK installation package
E.libs: If a third-party jar package is used in the project, the jar package will be placed in the Libs directory, and the jar packages placed in this directory are automatically added to the build path.
F.res: All the images, layouts, strings and other resources used in the project are placed in this directory, and the contents of the R.java mentioned above are automatically generated according to the files in this directory. There are many subdirectories under this directory, the images are placed in the drawable directory, the layouts are placed in the layout directory, and the strings are placed in the values directory.
G.androidmainfest.xml: This is the configuration file for the entire project, and all four components defined in the program need to be registered in this file. You can also add a permission statement to the app in this file. You can also reassign the minimum and target versions of the program that you specified when building the project.
H.project.properties: This file specifies the version of the SDK that is used to compile the program through a single line of code.
Third, how HelloWorld run up
First open the Androidmainfest.xml file to find the following code:
<activity android : Name= ". Mainactivity " android:label=" @string/ App_name " > <intent-filter > <action android:name= "Android.intent.action.MAIN" /> <category android:name= " Android.intent.category.LAUNCHER " /> </intent-filter> </activity>
This code indicates that the activity registered with mainactivity and not registered in Androidmainfest.xml is not available. Two lines of code in Intent-filter are important, <action android:name= "Android.intent.action.MAIN"/> and <category android:name= " Android.intent.category.LAUNCHER "/> said Mainactivity is the main activity of the project, click on the app icon on the phone, the first thing to start is this activity.
So what's the use of mainactivity? Activity is the façade of an Android application, and everything you see in the app is placed in the activity, so the interface that the program runs is mainactivity the activity. Mainactivity.java Code:
package ga.orlion.helloworld;import android.app.activity;import android.os.bundle;import android.view.menu;import android.view.menuitem;public class mainactivity extends activity {@Overrideprotected void oncreate (bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);} @Overridepublic boolean oncreateoptionsmenu (Menu menu) {// inflate the menu ; this adds items to the action bar if it is Present.getmenuinflater (). Inflate (r.menu.main, menu); return true;} @Overridepublic boolean onoptionsitemselected (Menuitem item) {// handle action bar item clicks here. The action bar will// automatically handle clicks on the home/up button, so long// as you Specify a parent activity in androidmanifest.xml.int id = item.getitemid (); if (id == r.id.action_settings) {return true;} return super.onoptionsitemselected (item);}}
The
Mainactivity is inherited from Activity,activity is a base class provided by the Android system, and all activities in our project must inherit it to have the properties of the activity. Then you can see that there are three methods in Mainactivity, Oncreateoptionsmenu () This method is used to create the menu, we can ignore it first, mainly look at the OnCreate () method, OnCreate () The method is a method that must be executed when the activity is created. The Android program is designed with logical and view separation, and does not recommend the direct write interface in activity, usually in the layout file and then introduced in the activity. The second line of the OnCreate () method invokes the Setcontentview () method, which is the method that introduces a activity_main layout to the current activity. The layout files are defined in the Res/layout directory. Open Activity_main.xml:
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android" xmlns:tools= "Http://schemas.android.com/tools" android:layout_width= "Match_parent" android:layout_height= "Match_parent" android:paddingbottom= "@ Dimen/activity_vertical_margin " android:paddingleft=" @dimen/activity_horizontal_margin " android:paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools:context= " Ga.orlion.helloworld.MainActivity " > <TextView android:layout_width= "Wrap_content" android: layout_height= "Wrap_content" android:text= "@string/hello_world" /></RelativeLayout>
What we need to explain here is that the helloworld! string we see in the program interface is not defined in this file but is defined separately in the Res/values/string.xml,
<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "App_name" >helloworld</string > <string name= "hello_world" >hello world!</string> <string name= "Action_settings" >Settings< /string></resources>
Referenced by "@string/hello_world" in the layout file activity_main.xml.
Res directory , all the folders beginning with drawable are stored in pictures, all folders beginning with the values are put strings, layout folder is used to put the layouts file, the menu folder is used to put menus file. So many drawable folders are designed to make programs compatible with more devices. In the production process, it is best to give a picture to provide a few different resolutions of the copy, in these folders, when the program is running according to the current device resolution automatically choose which folder to load the file. If only one resolution of the picture is placed in the drawable-hdpi folder is good.
A reference to the string can be obtained through R.string.hello_world in the code, and a reference to the string can be obtained through @string/hello_world in the XML.
Getting Started with Android (i)