Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you start an IntentService on a separate process?

  1. Is it possible to start an IntentService on a separate process? How? If so, is it mandatory to bind to it?
  2. Is it possible to start an IntentService on a separate process AND run it in the foreground?
  3. What's the difference between android:isolatedProcess and android:process? See: http://developer.android.com/guide/topics/manifest/service-element.html
like image 560
Andrés Pachon Avatar asked Sep 19 '12 21:09

Andrés Pachon


People also ask

How do you get a service to run in its own process?

If the name assigned to this attribute begins with a colon (':'), the service will run in its own separate process. If the process name begins with a lowercase character, the service will run in a global process of that name, provided that it has permission to do so.

What are the limitations of the IntentService?

Limitations / DrawbacksThe Service may block the Main Thread of the application. The IntentService cannot run tasks in parallel. Hence all the consecutive intents will go into the message queue for the worker thread and will execute sequentially.

What can I use instead of IntentService?

Consider using WorkManager or JobIntentService , which uses jobs instead of services when running on Android 8.0 or higher. IntentService is an extension of the Service component class that handles asynchronous requests (expressed as Intent s) on demand. Clients send requests through Context.


1 Answers

1) Is it possible to start an IntentService on a separate process? How? If so, is it mandatory to bind to it?

Yes, you can start an IntentService in a separate process. Simply add android:process=":whatever" to the manifest entry for that service.

No, you don't need to bind to it. You can communicate with it by sending it Intents using startService()

2) Is it possible to start an IntentService on a separate process AND run it in the foreground?

Yes (see above). To make your service run in the foreground it can call startForeground() whenever it wants to do that. The service itself is in control of whether it runs in the foreground or background.

3) What's the difference between android:isolatedProcess and android:process? See: http://developer.android.com/guide/topics/manifest/service-element.html

android:process allows you to control in which process each particular component runs (by specifying the name of the process). You can group components of your application to run in separate processes (for example, all UI components in one process and all services in another). The default behaviour is that all components of an application run in the same process.

android:isolatedProcess is a flag (true/false) that you can set if you want a particular service component to run in a separate process isolated from the rest of your application. The isolated process doesn't have any of the permissions that are granted to the rest of your application. Normally, permissions are granted to an application and all components of the application have all the permissions that the application gets. android:isolatedProcess is only available starting with API level 16 (Jellybean). See http://aleksmaus.blogspot.de/2012/09/a-feature-of-android-jelly-bean.html and Advantage of introducing Isolatedprocess tag within Services in JellyBean[Android]

like image 143
David Wasser Avatar answered Sep 20 '22 07:09

David Wasser