How do I pass a mutable list to a bundle?
You can do
//apply plugin: 'kotlin-android-extensions'
//androidExtensions {
// experimental = true
//}
apply plugin: 'kotlin-parcelize'
Then
@Parcelize
class RecipeTemplate : Parcelable {
var recipeHeader: String? = null
var recipeText: String? = null
var recipeImage: String? = null
var recipeKey: String? = null
}
Then
var bundle = Bundle().apply {
putParcelableArrayList("LIST", ArrayList<Parcelable>(fbModel.recipeArray))
}
This depends on what items you have in your list. Bundle
has a couple methods that allow you to place lists in it, for example putIntegerArrayList
and putStringArrayList
. If you need to use a custom type, you can make it Parcelable
and use putParcelableArrayList
.
Of course, all these methods as their name suggest take ArrayList
instances specifically, not just any MutableList
. So you can either change all your MutableList
usages to use ArrayList
instead, or you can create a new ArrayList
from your existing MutableList
when you're putting it in the bundle:
bundle.putParcelableArrayList("key", ArrayList(myParcelableList))