Activity restart on rotation Android

前端 未结 30 3829
花落未央
花落未央 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 05:09

    I just discovered this lore:

    For keeping the Activity alive through an orientation change, and handling it through onConfigurationChanged, the documentation and the code sample above suggest this in the Manifest file:

    
    

    which has the extra benefit that it always works.

    The bonus lore is that omitting the keyboardHidden may seem logical, but it causes failures in the emulator (for Android 2.1 at least): specifying only orientation will make the emulator call both OnCreate and onConfigurationChanged sometimes, and only OnCreate other times.

    I haven't seen the failure on a device, but I have heard about the emulator failing for others. So it's worth documenting.

提交回复
热议问题