Mark
09/18/2020, 4:09 AMLifecycleObserver
to observe the fragment lifecycle, but what I’m struggling with is a mechanism of how best to use these callbacks to control the work.Ian Lake
09/18/2020, 4:52 AMMark
09/18/2020, 4:57 AMRecyclerView
which shows a list of items initially in some plain state. In the background the viewmodel grabs more information about each item and periodically updates (via MutableStateFlow) that list (as it makes progress). Note - it is important the user can scroll to the end of the list without waiting for all the items to be fully processed.Ian Lake
09/18/2020, 5:05 AMMark
09/18/2020, 5:09 AMIan Lake
09/18/2020, 5:16 AMonBindViewHolder
when the item is null (i.e., when the item isn't loaded)Mark
09/18/2020, 5:24 AMMark
09/18/2020, 5:28 AMMark
09/18/2020, 6:29 AMLifecycleCoroutineScope.launchWhenStarted()
which uses a (internal) PausingDispatcher
to accomplish what I need.kristianconk
09/18/2020, 9:24 PMMark
09/19/2020, 1:48 AMlaunchWhenStarted()
. I found the launchWhenStarted()
approach helpful for when moving forward from the fragment and then back to it, but not for configuration changes because I guess a new lifecycleCoroutineScope
comes into play. So I ended up using the ViewModel
as a LifecycleObserver
approach. I used the callbacks to maintain a MutableStateFlow
and then used that to help control the long running task.