Put List into Bundle object

Viewed 5717

I want to add a List<CustomObject> into a Bundle object. This CustomObject implements the Parcelable interface. I've noticed that the Bundle object has a class that is hidden that allowed me to pass a List of objects.

/** {@hide} */
    @UnsupportedAppUsage
    public void putParcelableList(String key, List<? extends Parcelable> value) {
        unparcel();
        mMap.put(key, value);
        mFlags &= ~FLAG_HAS_FDS_KNOWN;
    }

However as we can see is hidden. How can I pass a List of CustomObjects? or how can I transform a list into an ArrayList using Kotlin?

2 Answers

You can transform list into Array using this code

val arrayList = ArrayList(list)

how can I transform a list into an ArrayList using Kotlin?

Just cast as ArrayList

val bundle = Bundle()
val list : List<CustomObject > = ArrayList<CustomObject>()
bundle.putParcelableArrayList("list", list as ArrayList<CustomObject>)
Related