0

I've been trying and searching how to store user input in an ArrayList of custom object. I've tried onSaveInstancestate with my custom object implement Parcelable. I have an activity for user input, this input goes into my custom object and then put into an ArrayList. I pass the arrayList from one activity to the other where i have an Listview that i wanna fill with the objects from my ArrayList. This all works fine but, when i go back to the activity to give new input it replaces the old. So it doesnt save the objects in the arrayList. Am I using the wrong tool and should I use SQLite instead? Or maybe, because I'm new to coding, i have missed something obvious that prevents it from working correctly.

I thought this "Saving Array In Activity" was going to be helpful so I used it but because Im not using a string object but my own object it might not for me?

Community
  • 1
  • 1
  • Would you like to save the information even after the app is closed, or only for the life-cycle of the application? If it's the former, could you please include the code for the model class that populates your `ArrayList` in your question? – PPartisan Aug 15 '16 at 16:38
  • You are right with you implementation but make sure you added code in onRestoreInstanceState also to refill old data. – Ramit Aug 15 '16 at 16:53

1 Answers1

0

It depends on the longevity/importance of the data itself, if it'll be used for a long period of time, then you should use SQLite.

From what you're saying, onSaveInstancestate sounds like the correct way for you to go. You can still make use of your own custom Object granted that object - granted that it implements android.os.Parcelable.

Passer by
  • 562
  • 9
  • 14