5

I have mutable Map as private var optionsList: MutableMap<String, List<String>> = mutableMapOf() and i need to send it to another activity , i used this :

        val optionsIntent = Intent(this@MainActivity, OptionsActivity::class.java)
        optionsIntent.putExtra(
            "optionsLi",optionsList)
        startActivity(optionsIntent)

And it gives me an error in putExtra, but I can't find anything that is like putMap or something to use.

Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116

1 Answers1

8

Use

private var optionsList: HashMap<String, List<String>> = hashMapOf()

Instead of

private var optionsList: MutableMap<String, List<String>> = mutableMapOf()

As HashMap implements the Serializable interface, which makes it easy to add it to an intent

Md. Asaduzzaman
  • 14,963
  • 2
  • 34
  • 46