旋转后恢复上下文操作模式

Restore Contextual Action Mode after rotation

我的 Activity 有一个带有 ActionBar 的 listView。当列表项被长按时,会触发上下文动作模式。但是,动作模式会在屏幕旋转过程中丢失。

我知道我可以通过在 onsaveInstanceState/restoreInstancestate 方法中重新触发动作模式来恢复状态。但是我想知道在Action模式下有没有内置的方法来恢复它的状态?

谢谢!

AndroidManifest.xml 中声明 android:configChanges 将指示 Activity 管理器不为那些配置更改重新创建您的 activity(默认行为),在这种情况下您的操作栏状态将被重置。

android:configChanges="orientation|screenSize"

默认情况下,此声明会将下一个生命周期回调路由到 onConfigurationChanged(),然后是 onResume()

If your application doesn't need to update resources during a specific configuration change and you have a performance limitation that requires you to avoid the activity restart, then you can declare that your activity handles the configuration change itself, which prevents the system from restarting your activity.

来源:http://developer.android.com/guide/topics/resources/runtime-changes.html