-2

When we start the service ( longer running operation) can we assign new process id to Service? ...or... compulsory same default process id (which Linux kernel assign to application when it is being started) is assigned by OS?

Hardik Gajera
  • 1,351
  • 1
  • 14
  • 21

1 Answers1

0

for your service which needs a different process id than your application, you can use android:process attribute.

As per the Android docs,

If the name assigned to this attribute begins with a colon (':'), a new process, private to the application, is created when it's needed and the service runs in that process.

This way, when your service is created, Android system should run it in a different process with different PID.

To cross-check/verify that your service indeed runs with different pid, you can use ps command from adb shell or use DDMS to see if your service runs with different process id.

As a side note: Running a service in its own process has the small advantages that the garbage collector for the service does not affect your application and that the memory footprint of the service is a bit smaller if it runs alone.

Reference: Android - How to decide whether to run a Service in a separate Process?

Community
  • 1
  • 1
AADProgramming
  • 6,077
  • 11
  • 38
  • 58