I tried storing array list data by using serializable and parcelable but in both case when I get the data using getParcelable and getSerializable. I am getting error due to @Deprecated or Type Mismatch.
val time1ArrayTennis: ArrayList<TimeArr>
time1ArrayTennis = savedInstanceState?.getSerializable("time1") as ArrayList<*>
//TimeArr is data class
data class TimeArr(
val time1 : Int
) : Serializable
Can someone please help how to in a simple way I can save and restore data when screen rotates? Thanks
It's unclear what is
TimeArrin your code snippet. Probably you're getting an error, because it doesn't implementParcelableinterface. So you have at least 2 options:Parcelableinterface for yourTimeArrclass. And then useoutState.putParcelableArrayList("time1", time1ArrayTennis)to store your array inActiivty.onSaveInstanceState()method. And then get it fromBundleafter Activity's recreation inonRestoreInstanceState(savedInstanceState: Bundle)Your ViewModel class:
Your Activity class: