How can an Android application have multiple processes?

I developed an Android application that has 1 process and 2 services. But I noticed that "Google Services" has 2 processes and 1 service. How can it have 2 processes? I read in Processes and Threads to try to understand more about processes. It talks about having a manifest entry, but without a concrete example, I donโ€™t understand this. Can someone explain how an Android application can have more than one process and provide a concrete example of this?

+7
source share
2 answers

You can specify android:process=":remote" in your manifest to trigger the action / service in a separate process.

"remote" is just the name of the remote process, and you can call it whatever you want. If you want multiple processes / services to run in the same process, just draw the same name.

 <activity android:name=".RemoteActivity" android:label="@string/app_name" android:process=":RemoteActivityProcess"/> 
+15
source

if you are looking for examples, check out the hogwarts library , it will provide you with programming opportunities with several processes in android.

Basically, there are the following things necessary to start a service in its own process.

  • in AndroidManifest.xml, make sure the service process attribute is ": remote" or something like this with the prefix ":"
  • use startService () to call the service from your activity.
  • use AIDL for ipc.
  • Make all switching between processes. (this is actually a requirement for point 3)
+2
source

All Articles