/LiveDataSample

A sample Android LiveData app to demonstrate the simple use of LiveData

Primary LanguageKotlin

LiveDataSample

A sample Android LiveData app to demonstrate the simple use of LiveData

This is the simplest-ever LiveData sample. It has one Activity and a ViewModel. ViewModel has a LiveData object which is observed by the Activity.

Android LiveData diagram

When you run the app, Activity simply sets a value for a TextView and assigns itself as an observer to the ViewModel:

Initial value

Then, when you tap the button, a new value is set from within the ViewModel and Activity is notified. As a result, the new value set is displayed on the Activity:

Value after LiveData changes value