I have an ArrayList of objects that have a name and an icon pointer and I want to save it in SharedPreferences. How can I do?
NOTE: I don’t want to use Database
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
So from the android developer site on Data Storage:
So I think it is okay since it is simply just key-value pairs which are persisted.
To the original poster, this is not that hard. You simply just iterate through your array list and add the items. In this example I use a map for simplicity but you can use an array list and change it appropriately:
You would do something similar to read the key-value pairs again. Let me know if this works.
Update: If you’re using API level 11 or later, there is a method to write out a String Set