Пробую передать list через onSaveInstanceState(), но почему-то не работает
class MainActivity : AppCompatActivity(), EditFragment.onSomeEventListener {
lateinit var mainBindingClass: ActivityMainBinding
private var list = ArrayList<String>()
private val detailFragment = DetailFragment()
private val editFragment = EditFragment()
lateinit var adapter: ArrayAdapter<String>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mainBindingClass = ActivityMainBinding.inflate(layoutInflater)
setContentView(mainBindingClass.root)
init()
initListeners()
}
override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
outState?.run {
putStringArrayList("sand", list)
}
super.onSaveInstanceState(outState, outPersistentState)
}
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
super.onRestoreInstanceState(savedInstanceState)
list = savedInstanceState?.getStringArrayList("sand") as ArrayList<String>
}
private fun init() {
adapter = ArrayAdapter(this, R.layout.my_list_item, list)
mainBindingClass.lvListOfNotes.adapter = adapter
}