findFragmentByTag() returns null after perform a FragmentTransaction using replace() method

前端 未结 8 1707
广开言路
广开言路 2020-11-30 04:44

My Android app consists three fragments: A, B and C. They\'re loaded in the two containers defined in the MainActivity layout.

When th

8条回答
  •  再見小時候
    2020-11-30 05:04

    In my case I used the code to replace and add to BackStack, but set wrong tag:

    val fragment = { SomeFragment.newInstance() }
    fragmentManager?.replaceAndAddToBackStack(R.id.container, fragment, WrongAnotherFragment.TAG)
    

    Of course, supportFragmentManager.findFragmentByTag(SomeFragment.TAG) didn't find SomeFragment.

提交回复
热议问题