Page MenuHomePhabricator

BaseActivity is receiving event multiple times per post of the event
Closed, InvalidPublic

Description

BaseActivity subscribes to app-wide events such as NetworkConnectEvent, ThemeChangeEvent, SplitLargeListsEvent etc. It receives these events multiple times per post.

Eg: Add a log message for the ThemeChangeEvent, which is posted only at one place. Trigered 3 times when posted only once when we change theme. Video : https://youtu.be/zwc9SX3mg8U

Initial research shows that this might be related to launch mode, activity lifecycle and register/unregistering the bus.

Event Timeline

I'm not sure there's anything unusual happening here...
An application can have multiple Activities open at the same time. When starting the app, it opens with MainActivity. When you go to Settings, it opens SettingsActivity on top of MainActivity. And when you go to change the theme, it opens ThemeFittingRoomActivity on top of the previous two. So, when changing the theme, you actually have three activities open. It therefore makes perfect sense to see three ThemeChange events, one caught by each open activity.

Correct. For the same reason, unregistering at onPause() is delegating it to just the actual activity that is active during posting, hence receiving only once. I have a patch up, changing just the callback, but will need to test it a bit before removing WIP on it.

In the case of ThemeChange events, we do actually want all activities to receive it, otherwise the paused activities won't change their theme to match the current selection.
For other events that need to be "exclusive" to the topmost activity (i.e. events that cause a dialog to be shown), we can just add a check for !isPaused() or something to that effect.

@Dbrant you are correct.. I tested and getting the event once per activity is actually what we are going for, so not a bug, closing this.