Hello, i need some help with child fragments. I’...
# android
k
Hello, i need some help with child fragments. I’ve a bottom sheet whose content is taken care by a child fragment. Can i pass this child fragment as an param in parent bottom sheet’s constructor given i create a FragmentFactory that takes this child fragment as an argument. This approach is also limiting because i cannot pass runtime arguments to the factory, and it gets plugged in the fragmentManager once. Would be REALLY HELPFUL if there are good sample on how to deal with child fragments, esp. when system kills the process.
😶 6
r
you should just need to use the childfragmentmanager to create the child fragment - if you want to communicate with the parent make a interface to pass rto the child on creation
for activity restart testing - use the developer setting "dont keep activities"
k
I do and that’s how the crash is happening. My parent fragment lies in a lower level module which is unaware of the implementation detail child fragments that lie in higher modules.
r
then its a matter of understand the activity restart process.. - if it's dialogs you can us dismissAllowingStateloss onStop
k
Hmm maybe thats something that might help let me look into this
r
see what fragment if being restarted - sometimes the data may not be available - trhe correct way is to use onSaveInstanceState to save restore data
k
Yea but in this case the thing to be restored is the child fragment, which i cannot persist in the bundle. I read there was a bug in childSupportFragment where it doesn’t retain the childFragment on process death (which is my case)
r
onSaveInstanceState should recurse through the fragment hierarchy
so you can do it in the fragment
k
That’s true, I’ll these steps and see if that’ll help
r
sometime you just need to save a db key or something and then you can reload fro persistence