禁用自动旋转等片段 [英] Disable other fragments in auto rotation

查看:169
本文介绍了禁用自动旋转等片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有各种片段的应用程序,问题是当手机旋转时,应用程序显示从一开始其他片段。它不会关闭当前的片段,但看起来像彼此顶部层。任何帮助,我会很感激。谢谢

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

推荐答案

您需要检查一个 savedInstanceState ,如果它存在,不重新创建片段。只是检查是否为空或不

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

如下图所示。

    @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
    }
    }

了解更多详情。

这篇关于禁用自动旋转等片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆