androidbroadcastreceiverbroadcastandroid-broadcaststicky-broadcast

Sticky broadcasts rebroadcast


I want to change the extras of a sticky broadcast, does another call to sendStickyBroadcast with the same intent creates a new sticky broadcast or replaces the previous one?

Also, I use sticky broadcast to maintain a state of some property and share the state to whoever wants it (services and activities), Is there a better approach to share a state of some property between all my android classes?


Solution

  • does another call to sendStickyBroadcast with the same intent creates a new sticky broadcast or replaces the previous one?

    it replaces the current one in case that the Intent is filter equal to the previous one that been already broadcast

    I would not use Sticky broadcast because it been deprecated from security reasons from android 5.

    also, from my experience - using sticky broadcast for the reason you describes can cause very easy to tons of bugs and unexpected behaviors if you are not considering every case the onReceive() can be called...

    Is there a better approach to share a state of some property between all my android classes?

    yes. there are much better ways to save state across different application components, depends on the specific use case: