Using the Android multi-process mechanism to split components

Source: Internet
Author: User

Android has a certain limit on memory, and the memory limit on many phones is completely different. Our application is actually a process, the process is completely independent, this process allocates memory is certain, so we often encounter oom problem. However, what you may not know is that you can specify that some components of the application run in different processes, rather than the one that is used to start the application.

The only thing we need is a property:

Android:process

This process property can be used for activities, services, content providers, and broadcast receivers and specific components that should be executed in the specified process.

In this example, I specify that Musicservice must perform the process in a separate "music":

<Manifest...>  <ApplicationAndroid:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/theme.main" >    <ActivityAndroid:name=". Musicactivity "      />    <ServiceAndroid:name=". Musicservice "android:process= ": Music"    />  </Application></Manifest>

So that we can put different components into different processes, and their own memory will become larger. However, there is the problem of how to communicate between multiple processes. Fortunately intent can "travel" across processes, handlers and messengers can also. You can also rely on aidl (Android Interface Definition language) and binder.

In short, everything is not absolute, this method is suitable for some of the layers are relatively clear and functionally independent modules, if you want to know more about this problem can refer to this article.

Reference from:

https://github.com/bboyfeiyu/android-tech-frontier/tree/master/androidweekly/%E6%AC%A2%E8%BF%8E%E6%9D%A5%E5%88 %b0android%e5%a4%9a%e8%bf%9b%e7%a8%8b%e6%97%b6%e4%bb%a3

Using the Android multi-process mechanism to split components

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.