在Android中处理方向变化的正确方法

在Android中处理方向变化的正确方法是什么? 当我研究这个问题时,有两种方法出现。

1st Method使用方法onSaveInstanceState(Bundle savedInstanceState)onRestoreInstanceState(Bundle savedInstanceState)来存储和恢复您的Activity在Android OS被方向改变后onRestoreInstanceState(Bundle savedInstanceState)之后。

android:configChanges="orientation|keyboardHidden" 方法将 android:configChanges="orientation|keyboardHidden"到您的AndroidManifest.xml中,以便在方向更改时不会销毁活动。

我已经尝试了两种方法,他们都工作,但第一种方法需要更长的时间来实现。 虽然我看到关于第二种方法的帖子,但我想知道这是否是处理方向更改的“接受”和“正确”方式。 每种方法的优点和缺点是什么? 谢谢!


第二种方法不允许你做特定的方向特定的东西,比如为屏幕旋转时加载不同的布局(我在这里考虑资源后缀)。 我没有遇到任何其他不良影响,但是文档声明:“应该避免使用这个属性,并且只能用作最后的手段。”

更多信息请访问:http://developer.android.com/guide/topics/resources/runtime-changes.html


请参阅http://developer.android.com/guide/topics/resources/runtime-changes.html,他们在这里解释两种方法并给出优缺点和最佳解决方案。

链接地址: http://www.djcxy.com/p/8107.html

上一篇: Proper Way of Handling an Orientation Change in Android

下一篇: Using OpenCL in the guest system with CPU on Virtual Box, VMWare or Parallels?