Activity restart on rotation Android

前端 未结 30 3915
花落未央
花落未央 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:15

    The approach is useful but is incomplete when using Fragments.

    Fragments usually get recreated on configuration change. If you don't wish this to happen, use

    setRetainInstance(true); in the Fragment's constructor(s)

    This will cause fragments to be retained during configuration change.

    http://developer.android.com/reference/android/app/Fragment.html#setRetainInstance(boolean)

提交回复
热议问题