easy way to save a LinkedList in a Android Application?

前端 未结 3 634
暗喜
暗喜 2021-01-22 16:07

what is the easyest or native way to save a list of objects in a android application?

i need to save it and then load it when the app starts again.

would be nice

3条回答
  •  迷失自我
    2021-01-22 16:19

    Let your items stored in the LinkedList implement Parcelable so you can put them in your bundle. The in onSaveInstance you can put your objects in the bundle using:

    bundle.putParcelableArrayList ("key", list);
    

    and in onRestoreInstanceState of your Activity get the data back from that bundle using :

    bundle.getParcelableArrayList();
    

提交回复
热议问题