Sorting and summary of application multi process in Android

preface

In computer operating system, process is the basic unit for resource allocation and scheduling. This is no exception for Android system based on Linux kernel. In the design of Android, an application has a (main) process by default. However, we can realize that one application corresponds to multiple processes through configuration.

This article will try to summarize the application multi process in Android.

android:process

A simple example of applying Android: process

What are the benefits of applying multiple processes

Increase app available memory

In Android, the system will allocate a certain amount of memory for each app by default. For example, from the earliest 16m to the later 32m or 48m. The specific memory size depends on the hardware and system version.

These limited memory is enough for ordinary apps, but it is really stretched for applications that display a large number of pictures.

After careful study, you will find that the restriction of the original system acts on the process (after all, the process is the basic unit of resource allocation). That is, if an application implements multiple processes, the application can get more memory.

Therefore, increasing the available memory of APP has become an important reason for multi process application.

Independent of the main process

In addition to increasing the available memory of the app, ensure the use of multiple processes, which can be independent of the main process to ensure the execution and completion of some tasks.

For a simple example, a previous project has the function of exiting, which is specifically implemented as killing the process. In order to ensure that some statistics are reported normally and not affected by the exit of the current process, we can use an independent process to complete it.

Shortcomings and shortcomings of multi process

Data sharing issues

SQLite is easily locked

Unnecessary initialization

Some simple code examples

Gets the current process name

Basic process initialization class

This class is used to initialize the business logic shared by each process.

Application of factory mode

Specific calling code

Do you need multiple processes

It depends on the specific situation to determine whether multiple processes are required.

Memory limit

In addition to memory limitations, you also need to consider whether you really need to perform some operations independently of the main process.

Other questions about Android: process

In the Android: process section, we mentioned that if the attribute value starts with a lowercase letter, it is a global process and can be shared by other applications.

The so-called sharing means that the components of different apps run in the same specified process.

Preparation conditions

Subject to the security mechanism of Android system, we need to do the following two preparation conditions.

Specific examples

The first app's manifest file, anotheractivity, runs in a process called droidyue.com.

The second app's manifest file, secondactivity, runs in a process called droidyue.com.

The anotheractivity and secondactivity above will run in a process called droidyue.com, although they are located in different apps.

However, this way of sharing processes will cause many problems, which is not recommended for everyone.

The above is my simple research on multiple processes in Android. If you have any questions, please correct them.

summary

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>