Introducing Service and IntentService
If the basic unit of a visible application is Activity
, its equivalent unit for non-visible components is Service
. Just like activities, services must be declared in the AndroidManifest
file so that the system is aware of them and can manage them for us.
<service android:name=".MyService"/>
Service
has lifecycle callback methods similar to those of Activity
, which are always invoked on the application's main thread.
Also, just like Activity
, Service
does not automatically entail a separate background thread or process, and performing intensive or blocking operations in a Service
callback method can lead to an Application Not Responding dialog.
However, there are several ways in which services are different to activities, listed as follows:
A
Service
does not provide a user interfaceThere can be many services active at the same time within an application
A
Service
can remain active even if the application hosting it is not the current foreground application...