title: How to save list items added to "Favorites" so that after closing the application they are not reset?
body: <p>Kotlin. I have a feature in my application to add list items to &quot;Favorites&quot;. As long as the application is open, items remain in Favorites. But as soon as I close it, the list of favorite items is reset to zero.</p>
  <p>How can I make my favorite list items persist after the application closes?</p>
  <pre><code>class MainActivity : AppCompatActivity() {
  
      var data = Data.initData()
  
      private val adapter by lazy {
          MainAdapter(data, { item -&gt;
              navigateToDetail(item)
          }, { index -&gt;
              swapData(index)
         }, true)
      }
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          supportActionBar?.title = getString(R.string.app_name)
          initList()
      }
  
      // list initialization on the main screen
      private fun initList() {
          val recyclerView: RecyclerView = findViewById&lt;RecyclerView&gt;(R.id.rv_main)
          recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
          recyclerView.adapter = adapter
      }
  
      // when clicking on &quot;Add to favorites&quot; you need to change isFavorite in a certain element of the list and notify the adapter about it
      private fun swapData(index: Int) {
          val itemClickedId = data[index].id
          val itemInList = data.first { data -&gt; data.id == itemClickedId }
          itemInList.isFavorite = !itemInList.isFavorite
          adapter.notifyItemChanged(index)
      }
  </code></pre>
  <p>Partial list code</p>
  <pre><code>package com.app.appfirst
  
  import android.os.Parcelable
  import kotlinx.parcelize.Parcelize
  
  @Parcelize
  data class Data(
      val id: Int,
      val fullWay: String,
      var isFavorite: Boolean,
      val detail: List&lt;Detail&gt;
  ): Parcelable {
      companion object {
          fun initData() =
              arrayListOf(
                  Data(1,
                      &quot;Moscow&quot;,
                      false,
                      arrayListOf(
                          Detail(
  </code></pre>