抄录了关于sendStickyBoradcast()的相关理解.
关于sendStickyBoradcast(),SDK中的相关说明:
[quote]Perform a sendBroadcast(Intent) that is "sticky," meaning 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).[/quote]
[quote]
These are broadcasts whose data is held by the system after being finished, so that clients can quickly retrieve that data without having to wait for the next broadcast.
[/quote]
上面的解释,不是特别好理解, 请看下面的解释.
[b]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. [/b]
[b]Heres an abstract example of how one might use a sticky broadcast:
Intent intent = new Intent("some.custom.action");
intent.putExtra("some_boolean", true);
sendStickyBroadcast(intent);
If you are listening for this broadcast in an Activity that was frozen (onPause), you could miss the actual event. This allows you to check the broadcast after it was fired (onResume).
EDIT: More on sticky boradcasts...
Also check out removeStickyBroadcast(Intent), and on API Level 5 +, isInitialStickyBroadcast() for usage in the Receiver's onReceive.[/b]
资料来源:
[url]http://stackoverflow.com/questions/3490913/what-is-a-sticky-intent-android[/url]
[url]http://stackoverflow.com/questions/2584497/what-is-the-difference-between-sendstickybroadcast-and-sendbroadcast-in-android[/url]
一个小的知识点整理,希望大家有用.
关于sendStickyBoradcast(),SDK中的相关说明:
[quote]Perform a sendBroadcast(Intent) that is "sticky," meaning 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).[/quote]
[quote]
These are broadcasts whose data is held by the system after being finished, so that clients can quickly retrieve that data without having to wait for the next broadcast.
[/quote]
上面的解释,不是特别好理解, 请看下面的解释.
[b]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. [/b]
[b]Heres an abstract example of how one might use a sticky broadcast:
Intent intent = new Intent("some.custom.action");
intent.putExtra("some_boolean", true);
sendStickyBroadcast(intent);
If you are listening for this broadcast in an Activity that was frozen (onPause), you could miss the actual event. This allows you to check the broadcast after it was fired (onResume).
EDIT: More on sticky boradcasts...
Also check out removeStickyBroadcast(Intent), and on API Level 5 +, isInitialStickyBroadcast() for usage in the Receiver's onReceive.[/b]
资料来源:
[url]http://stackoverflow.com/questions/3490913/what-is-a-sticky-intent-android[/url]
[url]http://stackoverflow.com/questions/2584497/what-is-the-difference-between-sendstickybroadcast-and-sendbroadcast-in-android[/url]
一个小的知识点整理,希望大家有用.