Can you explain the following terms: broadcast receiver and service? How do they relate to each other?
It makes the service to get and give. Can u please explain me in clear
- A broadcast receiver (receiver) will receive intents sent by sendBroadcast(). You need to register the broadcast receiver to receive the intents. An intent is an object storing information that can be passed in your application or to other applications. A receiver gets notified by the Android system if the specified event occurs.
To register a broadcast receiver, you need create a sub-class of BroadcastReceiver. You can either dynamically register the instance of this class with Context.registerReceiver() or statically publish an implementation through the <receiver> tag in your AndroidManifest.xml.
Here is an example to receive intents when the screen is off or on.
- A Service performs a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Each service class must have a corresponding
Here is an example of a Service to to detect screen on and screen off.
- The service can communicate with the broadcast receiver to notify an activity. An activity creates a window for you in which you can place your UI with setContentView(View).
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: