My app stores an ArrayList of custom Food objects which are posted to a ListView in the main Activity. The ListView portion of the app works perfectly, but I’m having an issue saving and loading these Food objects to and from SharedPreferences.
I’m saving these Food objects to SharedPreferences by saving each of its attributes as a String, putting them in a StringSet, and saving each one via the putStringSet function. When the app resumes, it reads through each StringSet from SharedPreferences and creates a new Food item with the read attributes, then adds each one to the ArrayList. The code seems like it should work, but just doesn’t load the data between sessions. Can anyone help me figure out why? Thank you!
Code removed
You seem to never instantiate foodNamesSet variable. Hence the check if(foodNamesSet != null) always return false. Same thing applies to other sets as well. Besides, I think you should do the logic in onPause() rather in onStop().