https://kotlinlang.org logo
#android
Title
# android
k

krtko

08/16/2018, 11:01 PM
I have been toying around with an idea to be able to directly pass arguments between Fragments. Could y'all let me know if its a bad idea or pointless? I would just love to find a solution that doesn't involve serial/deserialization of data into bundles. When the Fragment is first created, embed the a subclassed ViewModelProvider.Factory into the Fragment with the arguments you want to pass on. When the Fragment goes to get its ViewModel it'll use the embedded Factory which will pass on the arguments. If the factory isn't embedded it constructs a new one with default arguments. Since ViewModels survive configuration changes, the same ViewModel with the previous arguments will be used each time that Fragment gets recreated.
j

jw

08/16/2018, 11:04 PM
Two things: - This isn't Kotlin specific so probably not appropriate to discuss here. - You have to use the Bundle because those will survive process death through the activity saved instance state when Android kills your activity and restores it.
k

krtko

08/16/2018, 11:05 PM
Alright sorry to bring it up here. Thanks Jake
2 Views