Knowing about Sticky intent in Android

前端 未结 6 1790
后悔当初
后悔当初 2020-12-29 18:17

In android there are 3 kinds of Intents,

  1. Intent,
  2. Sticky Intent,
  3. Pending intent.

so What is sticky intent?

6条回答
  •  滥情空心
    2020-12-29 18:48

    An intent that is used with sticky broadcast, is called as sticky intent. This intent will stick with android system for future broadcast receiver requests.

    OR

    sendStickyBroadcast() performs a sendBroadcast(Intent) known as sticky, i.e. the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver(BroadcastReceiver, IntentFilter). In all other ways, this behaves the same as sendBroadcast(Intent). One example of a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED. When you call registerReceiver() for that action -- even with a null BroadcastReceiver -- you get the Intent that was last broadcast for that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.

提交回复
热议问题