SavedInstanceState is always null in fragment

后端 未结 5 1871
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 04:08

I have a fragment attached to the activity using XML (and setContentView() in activity). A have a problem because I have very dynamic views in my fragment, so when orientati

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 04:31

    I had a similar problem where I was always getting savedInstanceState as null inspite of supplying the bundle to the Fragment.

    The only solution that worked for me was to do

    myFragment.setArguments(bundle) 
    

    with my bundle from the Activity and do a

    Bundle bundle = this.getArguments();
    

    in onCreateView of the fragment.

    Hope this helps someone else.

提交回复
热议问题