Activity restart on rotation Android

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

    You may use ViewModel object in your activity.

    ViewModel objects are automatically retained during configuration changes so that data they hold is immediately available to the next activity or fragment instance. Read more:

    https://developer.android.com/topic/libraries/architecture/viewmodel

提交回复
热议问题