Join Slack
Powered by
Hi guys, i have a question about viewModel and fra...
# android
f
Francesco megna
07/31/2018, 9:48 AM
Hi guys, i have a question about viewModel and fragment, how i can share the same viewModel between more fragments?
h
Harun
07/31/2018, 9:50 AM
Yes you can
s
Saurabh Arora
07/31/2018, 10:04 AM
by using a ViewModelProvider of the parent activity instead of the Fragment
a
arekolek
07/31/2018, 10:08 AM
https://developer.android.com/topic/libraries/architecture/viewmodel#sharing
f
Francesco megna
07/31/2018, 1:31 PM
By the way i can use inheritence for that? Creating a BaseViewModel to share with my fragments
Francesco megna
07/31/2018, 1:32 PM
and at same point specify the fragment lifecycle instead of activity?
Open in Slack
Previous
Next