Tuesday 15 September 2015

What is a Sticky Intent?

Sticky Intent is also a type of Intent which allows a communication between function and a service sendStickyBroadcast() performs a sendBroadcast(Inent) know as sticky,the Intent your 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 isACTION_BATTARY_CHANGED.When you call registerReceiver() for that action — even with a null BroadcastReceiver — you get the Intent that was last Broadcast fot that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state change in the battery.

Syntax
Intent intent = new Intent("some.custom.action");
intent.putExtra("some_boolean", true);
sendStickyBroadcast(intent);

No comments:

Post a Comment

Ads Inside Post