Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a process and service?

I want to know what is the difference between a process and a service in an android app? I tried to study about this topic a lot, but did not clear my basics yet...please help?

like image 418
Rubal Avatar asked Nov 26 '14 14:11

Rubal


1 Answers

A process and a service are two different things:

What is a Service?

Most confusion about the Service class actually revolves around what it is not:

  • A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.
  • A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).

Thus a Service itself is actually very simple, providing two main features:

  • A facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). This corresponds to calls to Context.startService(), which ask the system to schedule work for the service, to be run until the service or someone else explicitly stop it.
  • A facility for an application to expose some of its functionality to other applications. This corresponds to calls to Context.bindService(), which allows a long-standing connection to be made to the service in order to interact with it.

source: http://developer.android.com/reference/android/app/Service.html

What is a Process

When an application component starts and the application does not have any other components running, the Android system starts a new Linux process for the application with a single thread of execution. By default, all components of the same application run in the same process and thread (called the "main" thread). If an application component starts and there already exists a process for that application (because another component from the application exists), then the component is started within that process and uses the same thread of execution. However, you can arrange for different components in your application to run in separate processes, and you can create additional threads for any process.

source: http://developer.android.com/guide/components/processes-and-threads.html#Processes

like image 75
peko Avatar answered Sep 29 '22 17:09

peko