Android Application Structure -- relatively biased test questions

Source: Internet
Author: User
Tags vector font

1. Android project file Composition
Expand the project in the package manager, as shown in:

Project Structure Analysis
The newly created Android project contains directories such as src, gen, bin, assets, bin, and res. AndroidMainifest. xml is required by the Android project, and other directories and files are optional.
Src directory
Src is just a directory for storing common Java source files.
Res directory
Res is a resource file that stores various Android projects. This directory stores all resources used by android applications, including image resources, string resources, style resources, and size resources.
Resources are divided into drawable, layout, menu, and values directories.
Drawable subdirectory
The drawablesub-directory specifies the main image resource file. The supported format is .png. jpg.
Drawable-ldpi, drawable-mdpi, drawable-hdpi, and drawable-xhdpi are used to store small, medium, large, and special image files.
Layout subdirectory
Layout stores the interface layout file.
Values stores resource files in Various xml formats, such
Dimens. xml size resource file;
String. xml string resource file;
Styles. xml style resource file;
Bin directory
BIND is used to store and generate target files, such as Java binary file packaging resource file (.apk suffix) and Dalvik Virtual Machine executable file (. dex suffix)
Gen directory
Gen is used to save Android to automatically generate an R. java configuration file.

AndroidManifest. xml (list file of the Android Application)
The AndroidManifest. xml file is the system list file of the Android project, which is required for each project.
The global description file of the Android project is used to control the overall attributes of the Android application, such as the name, icon, and access permission.
Information typically contained in the AndroidManifest. xml list
(1) package name of the application
(2) components included in the application
(3) The Minimum Version compatible with the application.
(4) Permission statement required by the application to use the system
(5) Permission declarations required by other programs to access the program
<! -- Specify the package name of the Android app --> <manifestxmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. example. hero"
Android: versionCode = "1"
Android: versionName = "1.0" type = "codeph" text = "/codeph">
<! -- Specify the minimum and maximum sdks supported by the project -->
<Uses-sdk
Android: minSdkVersion = "8"
Android: targetSdkVersion = "15"/>
<! -- Specify the Android app tag and icon -->
<Application
Android: icon = "@ drawable/ic_launcher"
Android: label = "@ string/app_name"
Android: theme = "@ style/AppTheme">
<! -- Define a COMPONENT Activity of the Android Application. The class of the activity is MainActivity and the tag of the Activity is specified. -->
<Activity
Android: name = ". MainActivity"
Android: label = "@ string/title_activity_main">
<Intent-filter>
<! -- Specify that the Activity is the entry of the program -->
<Actionandroid: name = "android. intent. action. MAIN"/>
<! -- Run the Activity when the application is specified -->
<Categoryandroid: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
</Activity>
</Application>
</Manifest>
AndroidManifest. xml permission description (for example, AndroidManifest. xml)
An Android application may need permissions to call the functions of the Android system. An Android application may also be called by other applications. Therefore, it also needs to declare the permissions required to call itself.
1. Declare the permissions of the application.
You can use the <manifest.../> element to add the <users-permission.../> sub-element to declare the permission.
<! -- Declare that the application has the permission to call itself -->
<Uses-permission android: name = "android. permission. CALL_PHONE"/>
2. Declare the permissions required to call the application.
Add the following code in the <activity.../> element:
<! -- Declare that the application has the permission to call itself -->
<Uses-permission android: name = "android. permission. CALL_PHONE"/>
Extended: Android usrs-prmission permission Overview
Automatically generated class R. java
Public final class R {
Public static final class attr {}
Public static final class dimen {
Public static final int padding_large = 0x7f040002;
Public static final int padding_medium = 0x7f040001;
Public static final int padding_small = 0x7f040000;
}
Public static final class drawable {
Public static final int ic_action_search = 0x7f020000;
Public static final int ic_launcher = 0x7f020001 ;}
Public static final class id {
Public static final int menu_settings = 0x7f080000 ;}
Public static final class layout {
Public static final int activity_main = 0x7f030000 ;}
Public static final class menu {
Public static final int activity_main = 0x7f070000 ;}
Public static final class string {
Public static final int app_name = 0x7f050000;
Public static final int hello_world = 0x7f050001;
Public static final int menu_settings = 0x7f050002;
Public static final int title_activity_main = 0x7f050003 ;}
Public static final class style {
Public static final int AppTheme = 0x7f060000 ;}}
R. java file (for example, description of the role of the R file)
The aapt tool is automatically generated based on the resource files in the application. Therefore, we can understand R. java as the resource Dictionary of the android application.
Two main rules for aapt to generate the R. java file:
(1) Each class corresponds to an internal class of the R class.
(2) Each specific resource item corresponds to a public static final int Field of the internal class.
As resources are constantly added to Android projects, more and more R. java files are available.
2. Android Architecture

The software hierarchy of Android includes an operating system, middleware, and application. The software hierarchy can be divided:
Applications
Application Framework
Runtime environments of various libraries and Android
Operating system layer
Application: it is written in java to Design User Interface interaction design. Android provides many core applications, such as desktops, contacts, telephones, and browsers.
Application Framework: Provides system APIs for applications. With the Android Application Framework, developers can reuse various components and services. Application Framework components:
UI components: including lists, text boxes, buttons, and other UI components, which are visible to users.
Content Providers: provides a mechanism for applications to access and share data.
Notification Manager: allows the application to display its warning information on the status bar. If the application receives a new message, it prompts the battery information.
Activity Manager: manages the lifecycle of an application and provides a page exit mechanism for the application.
Android library and runtime environment
Android contains some core C/C ++ libraries that can be used by various components of the system through JNI technology.
These libraries include:
System C Library: The Standard C library inherited from BSD.
Media Repository: includes a variety of commonly used audio, video format playback and recording. Supports static image files, including MPEG4, MP3, AAC, JPG, PNG, H.264, and AMR.
Surface Manager: manages the display subsystem and provides seamless integration of 2D and 3D for multiple applications.
LibWebCore: browser engine.
SGL: The underlying 2D graphics engine.
3D librarie: Provides 3D acceleration.
FreeType: Provides bitmap and vector font display.
SQLite: database application.
Android contains a core library that provides most of the functions of the core library of the java language.
Every Android application runs in its own process space and has an independent dalvik virtual machine. Dalvik is designed as a device to efficiently run multiple virtual systems at the same time. The dalvik virtual machine depends on some features of the Linux kernel, such as thread scheduling and memory management.
3. Composition of Android applications
The Android program consists of the following four parts:
Activity
Broadcast Intent Receiver er
Server
Content Provider
Activity generally represents a screen on the mobile phone screen, which is equivalent to a page in the browser. Add a view to the Activity to implement the application interface and user interaction. An application is generally composed of multiple activities, which can jump to each other and transmit data between pages. Each Activity has its own lifecycle.
Intent extends er, which is an abstract description of the operation to be executed. With Intent, you can jump between an Activity and an Activity. The most important component of Intent is its Action and data corresponding to the Action ). An Intent-related class is Intent Filters. It describes the operations that Intent can use to process.
Broadcast Intent Receiver, used to respond to external events. BroadcastReceiver cannot generate the UI, so it is invisible to users.
Service.
Content Provider: A Content Provider provides a set of standard interfaces that allow applications to save or read various data types of Content providers. An application can expose its own data. For external applications, it does not need to care about the data storage method. to store the data, you only need to access the data through the r interface provided by Content Provide. Of course, this involves data access permissions.

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.