Failure saving state - target not in fragment manager (setTargetFragment)

后端 未结 8 1412
北荒
北荒 2020-12-23 14:06

I\'ve got a monkey crash whereby

java.lang.IllegalStateException: Failure saving state: FragmentB has target not in fragment manager: FragmentA
at android.s         


        
相关标签:
8条回答
  • 2020-12-23 14:55

    I had this issue when showing a DialogFrament from another Fragment and using setTargetFragment on the DialogFragment. The issue was solved using getChildFragmentManager() when displaying the DialogFragment.

    1. ActivityA added FragmentA
    2. FragmentA added DialogFragmentB using ActivityA's FragmentManager.
    3. Called dialogFragmentB.setTargetFragment(fragmentA)
    4. Removed FragmentA and added new instance of FragmentA
    5. The FragmentManager associated with ActivityA still contained DialogFragmentB which had the first instance of FragmentA as target fragment.

    This caused "Failure saving state - target not in fragment manager" exception to be called.

    0 讨论(0)
  • 2020-12-23 14:56

    There were few changes regarding onSaveInstance() lifecycle order between Pre-HoneyComb and post-Honeycomb libraries. Please refer this article for more info:

    http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html

    0 讨论(0)
提交回复
热议问题