Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send MutableMap from activity to another with intent

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.

like image 624
Ahmed Wagdi Avatar asked Mar 04 '23 00:03

Ahmed Wagdi


1 Answers

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

like image 76
Md. Asaduzzaman Avatar answered Mar 05 '23 18:03

Md. Asaduzzaman