--

I’m not sure, in either case, if interruption is an issue. The main thread is still run, even if another app comes into the foreground.

In google’s scenario, this allows the view to notify the view model that the state has changed. In the event channel scenario coroutine cancellation is in play but you can chose to not cooperate with cancelation if you have critical things to do.

If you’re observing on the main thread then whatever work you’re doing has to be executed before the callback for onPause, onStop, etc is received. The app may be in the background but it still has some CPU time to notify the view model the state has been changed, or in the channel event scenario do whatever its going to do with the event.

What it means though, in either case, the event should be observed once and once only.

--

--

Michael Ferguson
Michael Ferguson

Written by Michael Ferguson

Android software developer. Views and opinions expressed are my own and not that of my employer.

No responses yet