How to get my bundle after i pass it in existing fragment without recreating it.I'm just showing and hiding my fragments. Methods onResume()
not calls, after transaction.commitNow()
. I thought about method update()
in fragment, but i can't create it in android Fragment.class
. How can i notify my existing fragment, that bundle have passed?
My navigator method in which i pass bundle
navigator:
@PublishedApi
internal fun goTo(tag: String,
keepState: Boolean,
withCustomAnimation: Boolean,
args: Bundle,
backStrategy: BackStrategy
){
if(activeTag == tag){
return
}
if(!fragmentMap.containsKey(tag) || !keepState) {
val fragment = Fragment.instantiate(activity, tag)
if (!args.isEmpty) {
fragment.arguments = args
}
if (!keepState) {
val weakFragment = fragmentManager.findFragmentByTag(tag)
weakFragment?.let {
fragmentManager.inTransaction {
remove(weakFragment)
}
}
}
fragmentManager.inTransaction {
addOpenAnimation(this, withCustomAnimation)
add(containerId, fragment, tag)
}
fragmentMap.put(tag, Screen(fragment, backStrategy))
if (activeTag == null) {
rootTag == tag
}
}else{
val fragment = fragmentMap[tag]?.fragment
if(!args.isEmpty){
fragment?.arguments = args
}
fragmentMap.put(tag, Screen(fragment!!, backStrategy))
if (activeTag == null) {
rootTag == tag
}
}
fragmentManager.inTransaction {
addOpenAnimation(this, withCustomAnimation)
fragmentMap
.filter {
it.key != tag
}
.forEach {
hide(it.value.fragment)
}
show(fragmentMap[tag]?.fragment)
commit()
}
activeTag = tag
invokeFragmentChangeListener(tag)
fragmentMap.replaceValue(tag, fragmentMap[tag])
}