user1958527
user1958527

Reputation: 3

Relationship between broadcast receiver and Service

Im confused with Service and Broadcast receiver.what is the relationship between these two?why we have to call broadcast receiver when we start a service.Can anyone kindly explain the concept between these two elements

Upvotes: 0

Views: 365

Answers (2)

sanjeev mk
sanjeev mk

Reputation: 4346

You don't have to register a BroadcastRecevier when you start a Service. That is, even if you don't register a BroadcastReceiver, our Service will work as expected. There is no must have dependency between the two.

As explained by Gridtestmail, a Service is a process you want to run in the background, without having an interface to the user.

A BroadcastReceiver is registered, when you want to be notified about certain events happening - for example, discovering a new bluetooth device or receiving an incoming call. If you register a BroadcastReceiver for receiving incoming calls , then your Receiver's onReceive() method is called whenever there is an incoming all, so you can process it. Similarly, for other event detection stuff.

I hope the concept is clear to you now.

Upvotes: 1

Gridtestmail
Gridtestmail

Reputation: 1479

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

Example : Service and BroadcastReceiver

Upvotes: 0

Related Questions