Help passing an ArrayList of Objects to a new Activity

前端 未结 10 2205
眼角桃花
眼角桃花 2020-11-28 08:53

I have an arraylist of objects. ie ArrayList.

I want to pass this to a new Activity. I tried to use putParcelableArrayList but it has issues with the object. I remov

10条回答
  •  温柔的废话
    2020-11-28 09:06

    1) Make sure the object you want to parcel has correctly implemented Parcelable

    2) Use this argument in putParcelableArrayList: new ArrayList<>(list)

    Example:

        protected void onSaveInstanceState(Bundle outstate) {
            super.onSaveInstanceState(outstate);
            outstate.putParcelableArrayList("myObjects", new ArrayList<>(myListOfObjects));
        }
    

提交回复
热议问题