How to send MutableMap from activity to another with intent

1.3k Views Asked by At

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.

1

There are 1 best solutions below

2
On BEST ANSWER

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