10 days to learn Android-fifth day

Source: Internet
Author: User

Original: 10 days to learn Android-fifth day

After a few days of practice, I believe you have a preliminary understanding of how to make a simple interface, and have made a good weather list.

Today we take a break, to practice less content, focusing on learning some theoretical knowledge, first to clarify several concepts.

Android System Architecture

Android system is essentially a Linux system, but compared to the Linux system, mainly in the drive, performance, memory management, device management and other parts of the more changes to more suitable for mobile devices.

As you can see, the Android architecture is four tiers, namely the Linux kernel, the system runtime, the application framework, and the application layer, each of which has the following roles:

Linux kernel

Provides the basic functionality that is required as an operating system, including various hardware drivers, memory management, power management, and so on, which is present as an abstraction layer between hardware and software.

System Runtime Library

System runtime is divided into two parts, the system library and Android runtime, the system library provides the underlying SQLite, SSL, OpenGL, Surface Manager and other class libraries, from the database to the network to the interface drawing, all at this level.

Android runtime, this part before Android4.4 is Dalvik, that is the Java virtual machine implemented by Google, all Android apps are running in the virtual machine, each Dalvik virtual machine is a separate process. Simply put, each Android app is packaged as an apk file, and the APK file contains resource files, code files (DEX), Androidmanifest.xml, and other configuration files, while the Dalvik virtual machine executes the Dex file.

After Android4.4, with the Dalvik virtual machine enabled, and the Android runtime instead, the new Android runtime will be more efficient, faster, consumes less power, and consumes lower memory, according to Google's instructions.

Application Framework

This layer is our code can be directly called, usually said Android API will be provided on this layer, mainly including activity manager, Window Manager, Content provider, etc., and so we have more learning system, Will slowly use some of the content.

Application Layer

This layer is the app we can usually operate. Android itself is not only an operating system, but also provides the basic app, such as SMS, Phone, browser, etc., of course, more apps are needed by our programmers to achieve.

Once you understand the infrastructure of the Android system, combine the weather forecast app that we're developing to learn more about one of the core file--androidmanifest.xml of the Android app project.

Androidmanifest

Each Android project contains a manifest (Manifest) file--androidmanifest.xml, which is stored at the very bottom of the project hierarchy, which is the global profile of the Android program that defines the structure and metadata of the application and its components. It contains the nodes that make up each component of the application (activity, service, content provider, and broadcast sink) and uses intent filters and permissions to determine how these components interact with each other and the other applications. It also provides a variety of properties to describe in detail the application's metadata (such as its icon or theme), as well as additional security settings and unit test top-level nodes that you can use, so let's take a look at this file for the weather app:

 <?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/        Android "package=" Com.demo.weather "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "android:targetsdkversion="/> <uses-permission android:name= "Android.permis" Sion. INTERNET "/> <application android:allowbackup=" true "android:icon=" @drawable/ic_launcher "an Droid:label= "@string/app_name" android:theme= "@style/apptheme" > <activity android:name= "Co                M.demo.weather.mainactivity "android:label=" @string/app_name "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "android.intent.ca Tegory. LAUNCHER "/> </intent-filter> </activity> </application></manifest> 

Let's explain it a bit,

Root node

The root node defines the package name, version number, where the packages must be unique, Android:versioncode is the version number that is used internally by the program, and Android:versionname is displayed to the user.

Uses-sdk

This node specifies the version of the SDK that needs to be used in the Android app, android:minsdkversion specifies the minimum version that can be run, and android:maxsdkversion specifies the highest version that can be run, Android: Targetsdkversion This specifies the target version.

The specified version is a number, you can refer to the following table:

Android version API level
5.0 21st
4.4w 20
4.4 19
4.3 18
4.2.2 17
4.1.2 16
4.0.3 15
4.0 14
3.2 13
3.1 12
3.0 11
2.3.3 10
2.2 8
2.1 7
1.6 4
1.5 3

About Android:targetsdkversion This target version many beginners will be puzzled, do not understand what is the use. My personal understanding is that your app specifies a minimum version of 8 and a target version of 19, and the program you make during the development process does not have any problems with the Android4.4 device, and the other versions of the Android system will be compatible with the corresponding compatibility. For example, some APIs are not available in the low version, we need to make version judgments in the program, to do different code processing. Note that this time you specify the minimum version is 8, you can use the minimum 8 API, when the program is compiled, you use the 19 API is not a compile error.

Android:maxsdkversion This configuration is generally not required, because the system itself is backwards compatible.

Uses-permission

This node specifies the permissions that the app has. The Android system is more restrictive for Rights management, and an app must declare permissions before it can use the appropriate functionality. For example, need to access the network, you need to declare a Android.permission.INTERNET right here, the corresponding such as GPS, Camera, vibrate and so on need to declare permissions before you can use.

Application

This node specifies the app's components, attributes, such as icon, label, name, theme, and so on.

Activity

This node is a child node of application, which defines all pages of the entire app.

Other

In addition to the above we use a few outside, there are receiver, provider, service, and so on, these we slowly familiar.

A Little practice

After understanding the architecture of Android itself, we slightly modified the manifest file.

App icon

Put the above icon in the Res\drawable-hdpi folder, and then modify the android:icon= under the application node "@drawable/ic_launcher" to android:icon= "@drawable/ Icon

App Name

Open a. res\values\strings.xml file, modify <string name= "App_name" >Weather</string> <string name= "App_name" > Weather </string>

After the call, run the program.

You can see that the icon and name in the upper-left corner of the app become what we want.

Today's content is relatively small, mainly some basic theoretical knowledge, but also hope that we have a lot of information, the structure of Android itself has more in-depth understanding.

The attachment is the project document, click Download.

This series of articles is my original, if need to reprint, please specify the source www.liuzhibang.cn

10 days to learn Android-fifth day

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.