Android concurrent programming: (1) Basic knowledge-start and end of the 1.2 program, android1.2

Source: Internet
Author: User

Android concurrent programming: (1) Basic knowledge-start and end of the 1.2 program, android1.2

All content in this section is original. If you need to reprint it, please indicate the source.

Http://blog.csdn.net/manoel/article/details/38471825


Android is a multi-user, multi-task system.

Multiple apps can be executed at the same time. switching between multiple programs does not have a significant delay.

Multi-task processing is performed by the Linux kernel, and program running is based on the Linux Process.

Linux Process

Linux assigns a unique User ID to each User to distinguish different users.

For permission reasons, each user can only access private resources, and no user (except Root user, that is, super administrator. We will not consider this user here .) You can access private resources of other users. Therefore, sandbox is used to separate these users.

In Android, each App has a unique user ID, that is, the App in Android corresponds to the user in Linux, and the App cannot access resources.

Android adds a Dalvik Virtual Machine for each process, that is, each app corresponds to a Dalvik virtual machine.

Shows the relationship between Linux processes, Dalvik virtual machines, and apps.

By default, the App and process have a one-to-one relationship.

However, if necessary, an App can run in several processes or several apps in the same process.

Lifecycle

The lifecycle of an App is encapsulated in its own Linux Process. From the Java perspective, it is the android. app. Application class.

When Dalvik calls the onCreate () method of Application, the Applicationg object is generated. Ideally, when Dalvik calls Application's onTerminate (), the app stops.

But remember, you cannot rely on this to determine that an Application object has been destroyed!

Because the potential Linux process may have been killed, Dalvik has not yet called onTerminate ().

In short, the Application object is the first instantiated object in a process, and the last object is destroyed.

App startup

When any component of an App is activated, the App is enabled.

All components are App portals. Remember, components include Activity, BroadcastReceiver, Service, and ContentProvider.

When the first component is activated, the Linux Process of the App is activated, unless the Linux Process is already running.

The process of enabling an App is summarized as follows:

  1. Enable the Linux Process.
  2. Create a Dalvik VM.
  3. Create an Application instance.
  4. Create an App entry component.

Creating a New Linux Process and a Dalvik virtual machine is not an instantaneous operation. This process reduces performance and has a slight impact on user experience.

Therefore, Linux can shorten the App startup time by enabling a special Zygote process during startup (system startup.

What is the problem. Zygote includes all the pre-loaded core databases. The new App process is incubated from this Zygote process, but the App process does not copy those pre-loaded core databases, instead, the core database of Zygote is shared.

This shortens the App startup time.

App termination

When the App is started, the Linux Process is created. When the system needs to recycle resources, the Linux Process ends. To ensure that the above process is not repeated every time the user enters the App. Dalvik will not destroy all the resources of the App if the resources are not actually insufficient. Therefore, even if all the components of an App are destroyed, the App will not end automatically.

When the system is in a shortage of resources, Dalvik is responsible for deciding which process to Kill. Which process is determined based on?

Based on App visibility and component running status, the system performs hierarchical processing on processes. That is to say, a low-level process is killed before a high-level process.

The following lists the process levels:

Foreground
The App has visible components in the front, or a Service is bound to a visible Activity in another process, or BroadcastReceiver is running.
Visible
The App has a partially visible component.
Service
The Service is running, but it is not bound to a visible component.
Background
Invisible Activity.
Empty
Processes without active components. Empty processes exist to improve the number of App launches, but they are killed first.


Reference http://developer.android.com/guide/components/processes-and-threads.html#Lifecycle


Error Message
Basic knowledge for Android mobile platform Program Development

It depends on the direction in which you want to develop. Android is a big thing, which can be divided into Application Layer Development, middle layer development, driver development, and system porting.

They also use different languages and do not know which direction you want to develop?

The application layer uses JAVA. The middle layer is C/C ++, and the bottom layer is C and assembly.

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.