开发者

What is the use of broadcast receiver in Android?

开发者 https://www.devze.com 2023-01-13 04:13 出处:网络
Can anybody tell what is the use of a BroadcastRece开发者_开发问答iver and give an example in Android?

Can anybody tell what is the use of a BroadcastRece开发者_开发问答iver and give an example in Android?

Can someone give a time zone change example using a BroadcastReceiver?


I think the android developers documentation explains it pretty good:

A broadcast receiver is a component that does nothing but receive and react to broadcast announcements. Many broadcasts originate in system code — for example, announcements that the timezone has changed, that the battery is low, that a picture has been taken, or that the user changed a language preference. Applications can also initiate broadcasts — for example, to let other applications know that some data has been downloaded to the device and is available for them to use.

(see developer.android.com)

On your android system broadcasts are used as an instrument of notifications. As the name suggests, they are broadcastet through your whole system. With a broadcast receiver you can catch these broadcast notifications.


Think about the broadcast receiver as a normal listener. If you listening for free beer and someone yells "free beer here", than you will react on that :) Thats your real life broadcast receiver example :D


A broadcast receiver is a component which allows us to register for system or application events. All registered receivers for an event will be notified by Android once this event happens. Android system periodically broadcast messages about things that are happening, such as the battery status changed, the Wi-Fi came on, or the phone’s orientation changed. You can pick up these state changes and perform actions after intercepting them and all this is done using broadcast receivers. Broadcast receivers receive and react to broadcasts generated by system or apps .

0

精彩评论

暂无评论...
验证码 换一张
取 消