Orientation change Crash Application

后端 未结 5 1259
慢半拍i
慢半拍i 2020-12-19 10:42

I am using fragments and when i change the orientation the application crash. Here is the log cat:

05-29 05:56:52.158: E/AndroidRuntime(1428): java.lang.Runt         


        
5条回答
  •  梦毁少年i
    2020-12-19 10:57

    
    

    Add this line to all your activities to avoid crash with orientation changes. This will avoid the activity being loaded again and again on orientation changes.


    For a little more information what you actually do with configChanges here the link to the Android documentation.

    Lists configuration changes that the activity will handle itself. When a configuration change occurs at runtime, the activity is shut down and restarted by default, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.

    Note: Using this attribute should be avoided and used only as a last resort. Please read Handling Runtime Changes for more information about how to properly handle a restart due to a configuration change.

    And how to handle configuration changes you can find here.

提交回复
热议问题