Android Services
Android Services
A Serviceis an application component that runs in the background, not interacting with the user, for an indefinite period of time.•Each service class must have a corresponding <service>declaration in its package's AndroidManifest.xml.
•Services can be started/stopped with
–Context.startService() and
–Context.bindService().
–stopService(…) and unbindService(…)
Services, like other application objects, run in the main thread of their hosting process.
•This means that, if your service is going to do any CPU intensive (such as MP3 playback) or blocking (such as networking, RSS exchange) operations, it should spawn its own thread in which to do that work
Android Broadcast Receiver
What is a BROADCASTRECEIVER?
•If an application wants to receive and respond to a global event, such as the phone ringing or an incoming text message, it must register as a BroadcastReceiver.
•An application registers to receive Intents by announcing in the AndroidManfest.xml file its IntentFilters.
•If the receiver is registered in the AndroidManifest.xml file, it does not have to be running in order to be triggered.
•When the global event occurs, the application is started automatically upon notification of the triggering event. All of this housekeeping is managed by the Android OS itself.
•An application may register at runtime via the Context class’s registerReceivermethod.
•If an application wants to receive and respond to a global event, such as the phone ringing or an incoming text message, it must register as a BroadcastReceiver.
•An application registers to receive Intents by announcing in the AndroidManfest.xml file its IntentFilters.
•If the receiver is registered in the AndroidManifest.xml file, it does not have to be running in order to be triggered.
•When the global event occurs, the application is started automatically upon notification of the triggering event. All of this housekeeping is managed by the Android OS itself.
•An application may register at runtime via the Context class’s registerReceivermethod.
BROADCASTRECEIVER and UI.
Like Services, BroadcastReceiversdo not have a UI.
•Of even more importance, the code running in the onReceivemethod of a BroadcastReceivershould make no assumptions about persistence or long-running operations.
•If the BroadcastReceiverrequires more than a trivial amount of code execution, it is recommended that the code initiate a request to a Serviceto complete the requested functionality.
0 comments: