0% found this document useful (0 votes)
6 views15 pages

Services in Android

Uploaded by

nandhaclaquiks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views15 pages

Services in Android

Uploaded by

nandhaclaquiks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

SERVICES IN ANDROID

UNIT-III
SERVICE IN ANDROID
• Android service is a component that is used to
perform operations on the background such
as playing music, handle network transactions,
interacting content providers etc.

• It doesn't has any UI (user interface).


2 States of Service
• Started Service (Unbounded Service)
• Bounded Service
Started Service (Unbounded Service)
• A service is started when component (like
activity) calls startService() method, now it
runs in the background indefinitely.

• It is stopped by stopService() method.

• The service can stop itself by calling


the stopSelf() method.
Bound Service

• A service is bound when another component (e.g.


client) calls bindService() method.

• The client can unbind the service by calling


the unbindService() method.

• A bound service offers a client-server interface that


allows components to interact with the service, send
requests, get results, and even do so across
processes with interprocess communication (IPC).
Methods in Services
onStartCommand()
• Such as an activity, requests that the service
be started, by calling startService().

• If you implement this method, it is your


responsibility to stop the service when its
work is done, by
calling stopSelf() or stopService() methods.
onBind()
• The system calls this method when another
component wants to bind with the service by
calling bindService().

• You must always implement this method, but


if you don't want to allow binding, then you
should return null.
onUnbind()
• The system calls this method when all clients
have disconnected from a particular interface
published by the service.
onRebind()
• The system calls this method when new clients
have connected to the service, after it had
previously been notified that all had
disconnected in its onUnbind.
onCreate()
• The system invokes this method to perform
one-time setup procedures when the service
is initially created (before it calls either
onStartCommand() or onBind()).

• If the service is already running, this method


is not called.
onDestroy()
• The system calls this method when the service
is no longer used and is being destroyed.
STATES IN ANDROID

•"States" refer to the conditions or phases an activity (or other components


like fragments) can be in during its lifecycle.

•These states dictate what the activity is currently doing and how it interacts
with the user and system resources.
•Active/Running: When an activity is in the foreground and the user is interacting with it.
This corresponds to the onResume() state in the lifecycle.

•Paused: When the activity is still visible but not in the foreground (e.g., when a dialog
appears). This corresponds to the onPause() state.

•Stopped: When the activity is completely obscured by another activity and is no longer
visible. This corresponds to the onStop() state.

•Destroyed: When the activity is finished or terminated by the system. This corresponds
to the onDestroy() state.

You might also like