umangburman / MVVM-Retrofit-Kotlin-Example

Android's MVVM Architecture in Kotlin ft. Retrofit
https://medium.com/@umang.burman.micro/androids-mvvm-architecture-in-kotlin-ft-retrofit-6acc22cabfc6
125 stars 29 forks source link

View Model class is storing the previous data even UI is not getting updated with new values #1

Open digmoy-techpro opened 3 years ago

digmoy-techpro commented 3 years ago

as per the tutorial i have followed, the all steps were working fine but while calling the same api twice or thrice, the data in the view model is not getting updated and user is getting the previous value only.

jarinrocks commented 2 years ago

@digmoy-techpro The approach used in this tutorial foe getting data from viewModel is wrong. We have to observe from the livedata.

It should be done as

mainActivityViewModel.getUser()

servicesLiveData.observe(this, Observer { serviceSetterGetter ->

            wp7progressBar.hideProgressBar()

            val msg = serviceSetterGetter.message

            lblResponse.text = msg

        })