Activity restart on rotation Android

前端 未结 30 3882
花落未央
花落未央 2020-11-21 04:32

In my Android application, when I rotate the device (slide out the keyboard) then my Activity is restarted (onCreate is called). Now, this is proba

30条回答
  •  庸人自扰
    2020-11-21 04:55

    Note: I post this answer if someone in the future face the same problem as me. For me the following line wasn't enought:

    android:configChanges="orientation"
    

    When I rotated the screen, the method `onConfigurationChanged(Configuration newConfig) did't get called.

    Solution: I also had to add "screenSize" even if the problem had to do with the orientation. So in the AndroidManifest.xml - file, add this:

    android:configChanges="keyboardHidden|orientation|screenSize"
    

    Then implement the method onConfigurationChanged(Configuration newConfig)

提交回复
热议问题