0

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])


}
Toper
  • 263
  • 5
  • 17

1 Answers1

0

You can get bundle in a fragment:

@Override
public void onCreate(Bundle savedInstanceState) {
    Bundle bundle = getArguments();
    ....
}

or just call your own method in fragment:

public void notifyBundleUpdated() {
    Bundle bundle = getArguments();
    ....
}
Dima Kozhevin
  • 3,602
  • 9
  • 39
  • 52
  • I can't . All my fragments extends from android-support Fragment.class. I don't have permission to my own methods – Toper Jul 13 '18 at 13:37
  • You can add your own methods into your class – Dima Kozhevin Jul 13 '18 at 13:42
  • i know, but i cant call it from `fragment` in `goTo` , because type of it is `supportFragment` – Toper Jul 13 '18 at 13:46
  • You might like [Dynamic cast in Kotlin](https://stackoverflow.com/q/41219748/3166697) and [How to check “instanceof ” class in kotlin?](https://stackoverflow.com/q/44098780/3166697) – Dima Kozhevin Jul 13 '18 at 13:52