A new MonitorViewModel starts at STOPPED and only learns otherwise from a broadcast. Local broadcasts aren't sticky, so two cases leave the UI wrong while the engine is fine:
- Android kills MainActivity under memory pressure while the foreground service keeps the process alive. The new activity gets fresh ViewModels and the service never says Running again.
- onStop unregisters the receivers, so anything that happens while the screen is off or another app is in front is lost. An engine error while backgrounded leaves the strip on Receiving.
Two possible solutions
- the activity asks the service for current state on start
- the service keeps the current state somewhere the ViewModels read directly
The first one just fixes engine state. The second one generally resolves this whole class of bug, since anything the UI reads from the service would always be current, rig status and frequency included. The second one seems like the better solutions but it's a bigger change so figured I'd get feedback first.
A new MonitorViewModel starts at STOPPED and only learns otherwise from a broadcast. Local broadcasts aren't sticky, so two cases leave the UI wrong while the engine is fine:
Two possible solutions
The first one just fixes engine state. The second one generally resolves this whole class of bug, since anything the UI reads from the service would always be current, rig status and frequency included. The second one seems like the better solutions but it's a bigger change so figured I'd get feedback first.