So the question is simple: When is it best to use a ViewModel and getting data from that versus using the newInstance function on a fragment and passing the data through the creation.
I've tried googling it, but there doesn't seem to be much out there. Not anything I can easily seem to find.
ViewModel
together with LiveData
will store the values throughout the life cycle of the Fragment/Activity. It can also observe the underlying data so when the ViewModel
changes your views will be automatically notified and updated. Read more about MVVM.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.