What would be an example of a mechanism that will replace Sticky Broadcasts?

202 views Asked by At

Sticky Broadcasts have been deprecated. The documentation says:

This method was deprecated in API level 21. Sticky broadcasts should not be used. 
They provide no security (anyone can access them), no protection (anyone can modify them), and many other problems. 
The recommended pattern is to use a non-sticky broadcast to report that something has changed, 
**with another mechanism for apps to retrieve the current value whenever desired**. 

What would be an possible example of such mechanism? What approach should I take?

1

There are 1 answers

0
danny117 On

Example of non sticky broadcast.

android.location.PROVIDERS_CHANGED

It means something has changed in the location provider the app has to check the providers to see what its current state is. It may be the user turned on the GPS radio in their device. The app doesn't know until it goes and checks the location providers.

Another problem with Sticky broadcasts is the information in the broadcast message could be stale.