Disable other fragments in auto rotation

耗尽温柔 提交于 2019-12-12 01:36:43

问题


i have an app with various fragments and the problem is when the phone rotates, the app displays other fragments from the begining. it does not close the current fragments but looks like layers on top of each other. any help i'd be grateful. thanks


回答1:


Try this to add in your AndroidManifest

     <Activity 
        ....
        ....
        android:configChanges="orientation|screenSize">



回答2:


You need to check for a savedInstanceState, and if it exists, don't re-create your fragments. just check if is null or not

as shown below

    @Override        
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            if (savedInstanceState == null) {
                 // Do your oncreate because there is no bundle   
            }else{
        // Do that needs to be done even if there is a saved instance, or do nothing
    }
    }

check this for more detail.



来源:https://stackoverflow.com/questions/34504679/disable-other-fragments-in-auto-rotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!