How to put a List in intent

后端 未结 5 1910
无人共我
无人共我 2020-11-29 11:28

I have a List in one of my activities and need to pass it to the next activity.

private List selectedData;  

I tried putting

5条回答
  •  青春惊慌失措
    2020-11-29 12:21

    Everyone says that you can use Serializable, but none mentioned that you can just cast the value to Serializable instead of list.

    intent.putExtra("selectedData", (Serializable) selectedData);
    

    Core's lists implementations already implement Serializable, so you're not bound to a specific implementation of list, but remember that you still can catch ClassCastException.

提交回复
热议问题