Eight of the pits in Android development: multi-process issues

Source: Internet
Author: User

This is a pit that needs to be handled carefully.

1 Memory:

In manifest, you can declare the process in which each component is located:

android:process= ": Name"

Then the corresponding acitivity, Receiver, service will run in the corresponding process.

But some classes run in all processes, such as some utils tool classes, such as the application class.

When encountering multiple processes in parallel, clarify the code for the process and avoid running process B's code in process a.

For example, there is a tool class Utils_proca. only need to work in process a , that for process B, this Utils_proca is not useful, is redundant code, if the Utils_proca is initialized in B , it consumes the CPU, also consumes memory.


2 Interaction:

In the same app, there are several different processes, and communication is a must.

There are a number of optional communication mechanisms between processes: Aidl, broadcast, and these two are Android-provided, well-understood communication mechanisms.

Use broadcast to guard against ANR and avoid processing time-consuming logic in OnReceive ().

With Aidl, there are some timing problems, and the bind service takes time. This time is uncertain, if the service process has not started at bind time, it will need to wait for the service process to start to complete. Therefore, bind may not immediately use aidl, waiting for the serviceconnection.onserviceconnected () callback to succeed.

If there is an immediate need to execute the service interface, either a callback, or another thread, round-robin determines whether the connection is OK. cut must not wait on the main thread. It will also be ANR.


Eight of the pits in Android development: multi-process issues

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.