1

I want any of application's Activities which is currently in foreground to receive a message.

So I'm sending a LocalBroadcastManager to distribute a message across my application. Then my idea was to have BaseActivity which all other Activities must extend. In the BaseActivity in onResume a receiver is registered (registerReceiver) for the message and it's unregistered (unregisterReceiver) in onPause.

This will work always but not when the message is distributed just in the time slot when transition between Activities is happening and the previous Activity is after it's onPause and next Activity is before its onResume.

So I wanted to use sendStickyBroadcast so that the message will wait until some Activity did not take it out, but I see

This method was deprecated in API level 21.

So how to ensure any of application's Activities which is currently in foreground to receive a message.

Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103

1 Answers1

1

This method was deprecated in API level 21.

Still, you can use if for a while. Deprecation does not automatically make feature unuseable.

So how to ensure any of application's Activities which is currently in foreground to receive a message.

You can switch to event bus lib like GreenRobot's EventBus and have activity state/lifecycle completely irrelevant

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • "Still, you can use if for a while. Deprecation does not automatically make feature unuseable." OK but deprecation is a big warning sign. Furthermore it was not deprecated without reason, especially as the comment in docs says "They provide no security (anyone can access them), no protection (anyone can modify them), and many other problems". But yeah, some sort of event bus whould do the trick. – Marian Paździoch Dec 18 '15 at 09:48