fragments and onConfigurationChanged

前端 未结 5 699
清歌不尽
清歌不尽 2021-02-06 07:00

I\'m trying to do something I do with activities, but within a fragment. What I do is using activities:

First stop the activity restarts when rotating the device a

5条回答
  •  春和景丽
    2021-02-06 08:05

    Maybe you can try use

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.frg.myFragment, container, false);
    }
    

    . In any case, the fragment still has to be destroyed and recreated, why not let Android handle it automatically by restarting the activity? If there is any data to keep, you can save it in onSavedInstanceState(). Setting android:configChanges="keyboardHidden|orientation|screenSize" is not recommended in Android.

提交回复
热议问题