Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Service and Broadcast receivers in android

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

like image 525
prago Avatar asked Jan 17 '12 05:01

prago


People also ask

What is broadcast receiver and service in Android?

A broadcast receiver (receiver) is an Android component which allows you to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens.

Why are services preferred over broadcast receiver for background applications?

Because services aren't directly visible, Android considers them less important than activities, so they'll be the first to be killed when your phone needs more memory. Broadcast receivers are the third kind of component. Like services, they only exist in the background and don't interact with you directly.

What is a broadcast receiver?

Broadcast Receiver Overview. A broadcast receiver is an Android component that allows an application to respond to messages (an Android Intent ) that are broadcast by the Android operating system or by an application.

What is broadcast receivers in Android with example?

Android BroadcastReceiver is a dormant component of android that listens to system-wide broadcast events or intents. When any of these events occur it brings the application into action by either creating a status bar notification or performing a task.


1 Answers

Service: If you want to do something in background , this will be running always in background even if the application closed. You can create this in separate process and also you can give your service to other app if you want. Downloading any content or Music is good example

Broadcast Reciever: Usually system will send some info which can be recieved by your app if you would wish to ,by registering. And you can do something what you want when that thing happens by using onReceive method. Example is the system will send BroadcastReceiver when new sms arrives or Booting done

Here is good article : Service and BroadcastReceiver

like image 107
Vins Avatar answered Sep 21 '22 11:09

Vins