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

59 views Asked by At

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.

1

There are 1 answers

1
Marcin Orlowski On

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