I have an ArrayList full of strings that the user populated it with to use in a different activity in a ListView to view the strings they have saved.
I want the ArrayList they populated to be saved but I am so lost on how to get it to work. I’ve tried FileOutputStream, SharedPreferences. I looked at many examples.
for example i have
ArrayList<String> give = new ArrayList<String>();
and to save the arraylist ive tried stuff like
FileOutputStream fos = openFileOutput(MYFILENAME, Context.MODE_PRIVATE);
fos.write(give.getBytes());
fos.close();
but this does not work at all
Here is some code to take a serializable object and write it to file, this maybe what you need. Tested it out with and ArrayList and it works fine. You can also modify the output and instead of writing it to file you can pass it to an activity using extras or its bundle. I used this method for android versions < 3.0.
To Read a file already containing serialized object:
To Write an object to file use:
Class to serialize an object: