package Ġcom . ch ic la im . jet pack . basic Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroidx . activity . view Models Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġcom . ch ic la im . jet pack . Base Activity Ċ import Ġcom . ch ic la im . jet pack . R Ċ import Ġcom . ch ic la im . jet pack . view model . LiveData ViewModel Ċ import Ġcom . ch ic la im . jet pack . view model . LiveData ViewModel Factory Ċ import Ġkotlinx . android . synt hetic . main . activity _ view model _ demo _ layout .* Ċ Ċ class ĠLive Data Demo Activity Ġ: ĠBase Activity () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġmy ViewModel : ĠLive Data ViewModel Ġby Ġview Models Ġ{ ĊĠĠĠĠĠĠĠ ĠLive Data ViewModel Factory () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ view model _ demo _ layout ) ĊĊĠĠĠĠĠĠĠ ĠLog . d (" LiveData Demo Activity "," onCreate Ġ$ this ") ĊĊĊĠĠĠĠĠĠĠ Ġmy ViewModel . live Data . observe ( this , ĠObserver < Int > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtext _ number . text Ġ= Ġ"$ it " ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d (" LiveData Demo Activity "," ${ lifecycle . currentState . name } Ġobserver Ġcallback Ġ$ this ") ĊĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠĠĠĠĠ Ġbtn _ plus . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmy ViewModel . plus ( 1 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonStart () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onStart () ĊĠĠĠĠĠĠĠ ĠLog . d (" LiveData Demo Activity "," onStart Ġ$ this ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Resume () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Resume () ĊĠĠĠĠĠĠĠ ĠLog . d (" LiveData Demo Activity "," on Resume Ġ$ this ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Pause () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Pause () ĊĠĠĠĠĠĠĠ ĠLog . d (" LiveData Demo Activity "," on Pause Ġ$ this ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Stop () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Stop () ĊĠĠĠĠĠĠĠ ĠLog . d (" LiveData Demo Activity "," on Stop Ġ$ this ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Destroy () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Destroy () ĊĠĠĠĠĠĠĠ ĠLog . d (" LiveData Demo Activity "," on Destroy Ġ$ this ") ĊĠĠĠ Ġ} ĊĊĊĊĊ Ċ }