Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can an Android application have more than one process?

Tags:

I have 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 did some reading at 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 get it. Can someone explain how an Android application can have more than 1 process and provide a concrete example of that?

like image 887
Marie Avatar asked Jul 04 '11 05:07

Marie


2 Answers

You can specify android:process=":remote" in your manifest to have an activity/service run in a seperate process.

The "remote" is just the name of the remote process, and you can call it whatever you want. If you want several activities/services to run in the same process, just give it the same name.

<activity android:name=".RemoteActivity" android:label="@string/app_name" android:process=":RemoteActivityProcess"/> 
like image 180
ddewaele Avatar answered Sep 21 '22 07:09

ddewaele


If you are looking for examples, do check out hogwarts library, it shall provide you facilities for multi-processes programming in Android.

Basically there are following things you need to have in order to run a service in its "own" process.

  1. in AndroidManifest.xml, make sure the service's process attribute is ":remote" or something like it with a ":" prefix
  2. use startService() calling to bring up the service from your activity.
  3. use AIDL for ipc.
  4. Make everything transfer between processes Parcelable. (this is actually the requirement for point 3)
like image 20
zhao chang Avatar answered Sep 17 '22 07:09

zhao chang