A service is a background component in Android that runs without direct user interaction. Services are used for repetitive or long-running tasks like downloading content or checking for new data. To create a custom service, it must be declared in the AndroidManifest.xml file and extend the Service class. A service can be started with startService(intent) and stopped with stopService(), and will call onStartCommand() each time it is started.
2. A service is a component which runs in
the background without direct interaction
with the user. As the service has no user
interface, it is not bound to the lifecycle
of an activity.
3. Services are used for repetitive and
potentially long running operations, i.e.,
Internet downloads, checking for new
data
10. An Android component (service,
receiver, activity) can trigger the
execution of a service via the
startService(intent) method
11. If the startService(intent) method is
called and the service is not yet
running, the service object is created
and the onCreate() method of the
service is called.
12. Once the service is started, the
onStartCommand(intent) method in
the service is called. It passes in the
Intent object from the startService
(intent) call.
13. If startService(intent) is called while
the service is running, its
onStartCommand() is also called.
Therefore your service needs to be
prepared that onStartCommand()
can be called several times.
14. You stop a service via the
stopService() method. No matter how
frequently you called the startService
(intent) method, one call to the
stopService() method stops the
service
15. A service can terminate itself by
calling the stopSelf() method. This is
typically done if the service finishes
its work.
17. By default, a service runs in the same
process as the main thread of the
application.
18. Therefore,you need to use asynchronous
processing in the service to perform
resource intensive tasks in the
background.
19. IntentService is a base class for Services
that handle asynchronous requests on
demand. Clients send requests through
startService(Intent) calls; the service is
started as needed, and stops itself when
it runs out of work.
20. Declares a broadcast receiver as one of
the application's components. Broadcast
receivers enable applications to receive
intents that are broadcast by the system
or by other applications, even when other
components of the application are not
running.
Receivers