why - Difference between Service and Broadcast receivers in android




why we use broadcast receiver in android (2)

Service is used when you want to do something in background, any long running process can be done using Service in Background. For example, you want to play music when your application gets close. In that case service will be running in background with music.

Example of Service

BroadcastReceiver is used when you want to fire some stuff or code during some event. For example, event can be on Boot of Device. If you want to perform something when device Boots, date and time changed etc...

Example of BroadcastReceiver

I want to know the difference between services and broadcast receivers, can anyone point out an example that can be observed on android mobile devices. Thanks


A broadcast receiver is an Android component which allows to register for system or application events. All registered receivers for an event will be notified by Android once this event happens.

A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.





broadcast