Android Activity: launch network task when data received from ViewModel
In an Android Views App with kotlin coroutines and ViewModel collecting data from a DataStore repository, I need to connect to a Bluetooth device when these data are received. What I have done:
SettingsViewModel
@HiltViewModel
class SettingsViewModel @Inject constructor(
private val myRepository: MyRepository
) : ViewModel() {
val setting1State : StateFlow = myRepository.getSetting1().stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5000),
""
)...