Building a Broadcast Receiver in Android with LiveData and Jetpack Compose

Опубликовано: 04 Май 2022
на канале: Brandan Jones
3,233
40

Create a BroadcastReceiver that listens to power connected (plugged in) and power disconnected (not plugged in) to simulate the response an Android application can have when it receives an external stimuli, like Bluetooth connection. When power is plugged in, the Broadcast Receiver updates a MutableLiveData boolean in the ViewModel. The Jetpack Compose user interface is using observeAsState() to watch this value as it changes, and it switches to a more simple user interface.