【问题标题】:Android, When the screen orientation changes, the app freezesAndroid,当屏幕方向改变时,应用程序冻结
【发布时间】:2011-11-15 15:41:35
【问题描述】:

当应用中的屏幕方向发生变化时,应用会冻结。纵向和横向模式都有 xml 文件。因此,当方向改变但应用冻结时,UI 会进行调整。

public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.main);    

【问题讨论】:

  • 一段时间后(几分钟后)是否正常工作......?
  • @Noby,它不起作用。据我所知,一旦我调用 setContentView(R.layout.main); 就必须重新初始化视图元素;然后它工作正常..

标签: android orientation


【解决方案1】:

如果您的意思是侦听器和其他处理程序不起作用,则通过冻结,这是因为在 setContentView(R.layout.main) 之后您有 rto 初始化视图,例如

button btn = findViewById();
btn.setOnClickListener();

【讨论】:

    【解决方案2】:

    如果您已经在 onCreate(Bundle) 方法中拥有 setContentView(R.layout.main),请从 onConfigurationChanged(Configuration) 方法中删除它。

    您似乎调用了两次 setContentView(R.layout.main)。

    【讨论】:

      【解决方案3】:

      在 Android 中处理重定向的默认方式是销毁并再次创建活动。您可能在 onCreate 中有一个缓慢的过程?如果是这样,您必须保存在 onSaveInstanceState(Bundle) 中处理的值,并在 onCreate 时恢复信息作为 exlain google here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-11
        • 1970-01-01
        相关资源
        最近更新 更多