Home > Software design >  Loading data only once in Android with ViewModel
Loading data only once in Android with ViewModel

Time:10-06

I have an Android app with a main fragment that you can navigate from using navigation graph. Data is loaded when the main fragment is opened. The problem is when I navigate from it and go back the data is loaded again, because fragment is recreated. How is it possible to load data only once?

CodePudding user response:

You can use ViewModel with the app and make a check if the ViewModel is already created do not load the data again

CodePudding user response:

I suggest to you use SingleLiveEvent it will fix your problem please check this

Medium

StackOverFlow

  • Related