Android Multi-process data summary _android

Source: Internet
Author: User

Warm to know the new

There are a lot of articles on the web, but basically they are talking about deep things, this is a need to study, and I was to this article is used to lazy (application level), records are their own understanding of the process of many, convenient to use when to lazy, if wrong, please advise, small programmer extremely grateful.

To talk about the process, first answer the following questions:

1. What is a thread?

A thread is a flow control that is performed separately in a program.

2. What is multithreading?

Multithreading is the execution of multiple flow controls in a single program. The role is to maximize the use of CPU resources.

3. What is a process?

Generally refers to an execution unit, an application (Android is an application).

4. What is the relationship between threads and processes?

A process can have more than one thread, and a process and a thread are included with the contained relationship.

5. Why do you use multiple processes?

1. The single process is not allocating enough memory to require more memory.
2. Need to run a separate component.
3. Do something that is not visible to people, such as (
A-> Heartbeat->b, if B does not start, start B.
B-> Heartbeat->a, if a does not start, start a.
Simply put, the double daemon prevents the user from being killed. )

6. How do I start multiple processes?

Set android:process= ": Remote" in Androidmanifest.xml

<service
  android:name= ". Remoteservice"
  android:label= "@string/app_name" android:process= "
  : Remote "/>

Start this service in activity

Intent mintent = new Intent (this, remoteservice.class);
StartService (mintent);

7. ": Remote", what kind of a colon is a ghost?

It's not a ghost, Android:process says this component runs in the process of what, is the process name. Use: means that this is a process that is private to the application that launches it. Similar to our registered activity omitting the package name. If our package name is com.example.whitelaning, the name of the android:process= ": remote" process is "com.example.whitelaning:remote".

8. What is the difference between a private process and a global process?

I want to know,%>_<%, someone knows.
The night rain sends the big reply of Peking University, E-Band: The representation is the current application of the private process, the other application components can not run with it in the same process, and for the global process, other applications can be in the same process through shareuid with the same UID application can share data, can access each other's private data (the Chairman's book is explained in the multi-process section)

9. What are the multiple processes to be aware of?

1. Each time you open a multiple process, application will be executed again, so if you do a lot of initialization work in application, then you need to determine which process started the application.

Method:

public class MyApplication extends application {

  @Override public
  void OnCreate () {
    super.oncreate ();
    int pid = Android.os.Process.myPid ();

    String processnamestring = "";
    Activitymanager Mactivitymanager = (activitymanager) this.getsystemservice (Getapplicationcontext (). Activity_service);

    For (Activitymanager.runningappprocessinfo appProcess:mActivityManager.getRunningAppProcesses ()) {
      if ( Appprocess.pid = = pid) {
        processnamestring = Appprocess.processname
      ;
    }

    } if ("Com.example.whitelaning". Equals (processnamestring)) {
      //do something
    } else {
      //do something
    }
  }
}

2. Multiple processes can invalidate a single case pattern because the memory of two threads is isolated.

10. What else do you want to know?

To see the source, you will die, if not dead, please tell me the private process and the global process of the difference, I will offer my year's knee

Through this article I hope to be able to master the information of Android multithreading, thank you for your support for this site!

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.