K
K
KnightForce2015-05-06 23:43:59
Android
KnightForce, 2015-05-06 23:43:59

Explain how sticky intents work?

Explain how sticky intents work?
I understand what happens when registering a BroadcastReceiver, when sendingBroadcast, etc.
But here, for example, in the book there is an example:

IntentFilter batIntentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent battery = context.registerReceiver(null, batIntentFilter);
int status = battery.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = ((status == BatteryManager.BATTERY_STATUS_CHARGING) || (status == BatteryManager.BATTERY_STATUS_FULL));

An IntentFilter is created, then the BroadcastReceiver registration method is called, but null is passed to it instead of a receiver. It must be passed a BroadcastReceiver and an IntentFilter for it to register.
But, as I understand from the documentation, if you pass null, sticky intent will return. And what does he do? Why is he? How is it applied?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2015-05-06
@onepavel

If I understand correctly, when registerReceiver(null, batIntentFilter) is called, the last intent that was previously sent for this filter intent will be returned. This last intent of the campaign is called sticky intent

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question