• 11
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

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

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

  • 39
Reply Report

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

  • 27
Reply Report
    • The difference here is of course obvious but there's 1 usage making the 2 becoming similar in the help of receiving some event. I found that usage of Service when starting to learn about Push Notification using GCM. On the client side they have 2 services GcmListenerService and InstanceIdListenerService - of course we need to use services here so that they can run in background, but in this case they behave much like what a BroadcastReceiver does, there are callbacks similar to OnReceive and they are fired per some broadcast Intent (specified via IntentFilter).