Activity restart on rotation Android

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

    One of the best component of android architechure introduce by google will fulfill your all the requirement that is ViewModel.

    That is designed to store and manage UI related data in lifecycle way plus that will allow data to survive as screen rotates

    class MyViewModel : ViewModel() {
    

    Please refer this:https://developer.android.com/topic/libraries/architecture/viewmodel

提交回复
热议问题