Search code examples
androidandroid-actionbarandroid-actionmode

Restore Contextual Action Mode after rotation


My Activity has a listView with an ActionBar. When the list item is long clicked, it will trigger the contextual action mode. However, the action mode will be lost during the screen rotation.

I know I can restore the state by re-triggerring the Action mode in onsaveInstanceState/restoreInstancestate methods. But I wondering is there any built-in method in Action mode to restore its state?

Thanks!


Solution

  • Declaring android:configChanges in AndroidManifest.xml will instruct Activity Manager to not recreating your activity (default behavior) for those config changes, in which case your action bar state will be reset.

    android:configChanges="orientation|screenSize"
    

    By default, this declaration will route the next lifecycle callback to onConfigurationChanged(), then 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.

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