Activity restart on rotation Android

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

    People are saying that you should use

    android:configChanges="keyboardHidden|orientation"
    

    But the best and most professional way to handle rotation in Android is to use the Loader class. It's not a famous class(I don't know why), but it is way better than the AsyncTask. For more information, you can read the Android tutorials found in Udacity's Android courses.

    Of course, as another way, you could store the values or the views with onSaveInstanceState and read them with onRestoreInstanceState. It's up to you really.

提交回复
热议问题