【问题标题】:onConfigurationChanged screen stopped rotating on device. Works on emulatoronConfigurationChanged 屏幕停止在设备上旋转。在模拟器上工作
【发布时间】:2011-12-24 03:14:23
【问题描述】:

我想阻止我的活动在每次方向改变时刷新。我通过实施实现了这一点。

@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig);

// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
    Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
} }

但是,当我删除 IF 代码以显示 Toast 时,它停止工作。屏幕开始在设备上刷新。这在模拟器上运行良好。

有人遇到过这种问题吗?

【问题讨论】:

  • 这是一个android开发网站developer.android.com/guide/topics/resources/…
  • 但您的清单中仍有 android:configChanges="orientation" 用于该活动?
  • 是的,我在清单文件中有 android:configChanges="keyboardHidden|orientation"。

标签: android android-layout android-emulator


【解决方案1】:

我终于通过使用解决了这个问题

protected void onSaveInstanceState(Bundle outState) {

webView.saveState(outState);

}

http://roman-dotnet.blogspot.com/2011/05/android-webview-orientation-changes.html

【讨论】:

    【解决方案2】:

    确保您没有调用 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);任何地方。这将导致 onConfigurationChange() 不会触发。

    放入一些日志语句以检查以确保它正在触发(并在 onCreate 中放入一些日志语句以检查以确保在配置更改期间它是否正在触发。

    See this Question.

    【讨论】:

      猜你喜欢
      • 2013-02-20
      • 1970-01-01
      • 2015-09-20
      • 1970-01-01
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      • 2012-08-19
      • 2023-03-23
      相关资源
      最近更新 更多