do you guys think its better to send a bundle to e...
# android
w
do you guys think its better to send a bundle to each fragment (that requires identifiers about things they are showing) or to use some injected object that holds this state for each fragment, which the fragment can refer to
l
I think an object might be cleared, right?
w
what do you mean by cleared @LeoColman
im currently using the bundle approach but its just getting to be a lot with many fragments requiring the info
l
I think objects might be garbage collected, for example, and you may lose your state over time
Perhaps you can wrap your bundle in an utility class?
p
sending bundles is redundant with view model shared by fragments, it’s better to hold such state in
LiveData
or
BehaviorRelay
l
Perhaps they're not using mvvm
p
actually it’s applicable to mvp or mvi too, the idea is just to have an observable state, with or without either architecture components or RxJava
w
i am using mvvm
and currently i have a unique view model per fragment. is the idea here to share a view model that holds this state?
p
exactly
it fits single-activity approach and works with navigation component
w
interesting idea - i haven't thought about sharing view models this way before but i suppose it does make sense. thanks
j
i aggree with pawel, sharing viewmodels is easier to use, particularly it's easier to inject a viewmodel rather than passing an argument over a couple of fragments that said you can make arguments easier to use, by using a readwritepropery, e.g. https://github.com/exozet/AndroidCore/blob/master/core/src/main/java/com/exozet/android/core/storage/FragmentArgumentDelegate.kt
p
I use MVVM pattern but not the architecture components. For flows within one activity that needs a state object I still pass the bundle up then assign in into the VM for the fragment which inherits from a BASE VM for the flow. Not sure if this helps
w
in order for this to work, the vm would have to live in my god activity right?
p
yes,
ViewModel
needs to be bound to activity in case to be shared by fragments