1. System Architecture
Android's overall system architecture consists of four large layers:
1) Linux kernel
Android is built on a more stable basis: the Linux kernel. Android uses Linux to complete its memory management, process management, networking, and other operating system services. Some of the utilities needed during development are dealing with Linux, such as the adb shell command, which opens a Linux shell where you can enter additional commands to run on the device.
2) Native Library
The Linux kernel layer above contains the Android native library, which is written in the C or C + + language and compiled for the specific hardware architecture used by the phone, and has been preinstalled by the handset manufacturer on the phone. Some of the most important native libraries include: Interface Manager, 2D and 3D graphics, media codecs, SQL database, and five parts of the Java Core library included with Android.
3) Application Framework
Above the native library and runtime are the application framework layers, which provide the various advanced building blocks needed to create the application, including the active manager, the content provider, the resource manager, the location manager, and the five most important parts of the notification Manager.
4) Applications and widgets
The top tier is the application and widget layer, which is a program that interacts with the user, and the widget can only be manipulated in a small rectangular box in the main application screen.
2. Window Management
Android has a foreground application, which usually takes up all the screen space except the status bar, and when the user starts up, the first app to see is the home app. When the user runs the application, Android launches the program and places it in the foreground. All programs and windows are recorded in the application stack by the system's activity manager, and the user can press the back button at any time to return to the previous window in the stack.
Internally, each user interface window is represented by an activity class, and each activity has its own life cycle. In Android, even if its process is ended, the application is still alive, the life cycle of the activity is not related to the life cycle of the process, and the process is simply a container for the various activities to be used freely.
Each activity in the Android program processes one of the following States during its existence, and the developer is notified by the OnXxx () method when the state is changed:
1) onCreate (Bundle): This method is called when the activity is first started and can be used to perform some initialization operations.
2) OnStart (): This method describes the activity that will be displayed to the user.
3) Onresume (): This method is called when the user can start interacting with the activity.
4) OnPause (): The method is run when the activity is going to be in the background.
5) OnStop (): The method can be called when the user no longer sees an activity, or when an activity is not needed for a period of time.
6) Onrestart (): If the method is called, indicates that the activity that has processed the stop state will be displayed again.
7) OnDestroy (): This method is called before the activity is destroyed.
8) Onsaveinstancestate (Bundle): The role of Android calls this method is to allow an activity to save the state of each instance.
9) Onrestoreinstancestate (Bundle): This method is called when an activity is reinitialized with a previously saved state using the Onsaveinstancestate () method.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/37/F8/wKiom1Oxc7LjSEnGAAGpbWagz4E134.jpg "title=" Other-pic.jpg "alt=" wkiom1oxc7ljsengaagpbwagz4e134.jpg "/> Activities that do not run in the foreground may be stopped, or the Linux process that holds these activities is ended, freeing up space for new activities, Sometimes the OnPause () method may be the last method called in the activity, so you should save any data that you want to continue to use the next time in the method.
3. Building Blocks
Some of the most important objects in Android are activities, intentions, services, and content providers. An activity is a user interface screen where an application can define one or more activities to handle the different stages of a program, each of which saves its own state in order to restore those states later. Intent is a mechanism for describing specific actions, such as taking pictures, dialing a phone, and so on, almost everything in Android goes through the intent phase, so there are many opportunities to replace or reuse many components. A service is a task that runs in the background without having to interact directly with the user, like a UNIX daemon. A content provider is a set of data encapsulated in a custom API that can read the data and write data to the API, which is the best way to share global data between applications.
A resource is a localized text string, bitmap, or other small amount of non-code information that a program needs. When the program is generated, all the required resources are compiled into the application. Resources are created by developers and stored in the Res directory within the project, and the android resource compiler processes these resources based on the subfolders of the resource and the format of the files, and can add suffixes to the resource directory names to support custom resources for specific languages, screen orientations, or pixel densities. The resource compiler compresses and packages the resources and generates a class called R that contains identifiers that can be used to reference those resources in the program, so Android ensures that all references are valid and saves space because it does not have to store all of these resource keys.
4. Security
Each application runs in its own Linux process, and the hardware prohibits one process from accessing the memory of other processes. Each application is assigned a specific user ID, and any file created by an application cannot be read or written by another application. In addition, access to certain critical operations is limited and must be explicitly requested in a file named Androidmanifest.xml. When you install an application, the Package Manager grants or does not grant these permissions based on certificates and user prompts, and the following are some common permissions:
1) Internet: access to the Internet.
2) Read_contacts: Read (but not write) the user's contact data.
3) Write_contacts: write (but not read) the user's contact data.
4) Receive_sms: Monitor incoming SMS messages.
5) Access_coarse_location: Use less precise location providers, such as cell phone base stations or Wi-Fi.
6) Access_fine_location: Use more precise location providers, such as GPS.
Android can even restrict access to parts of the entire system by using XML tags in androidmanifest.xml to restrict who can initiate activities, start services or bind to services, broadcast intentions to receivers, or access data from content providers.
This article from "Fangyuan" blog, declined reprint!