I am working on an app which is able to play a list of songs. It is not primarily a music player and so multiple playlists are not required. I have been using SharedPreferences to store a list of the songs which the user has selected from their MediaStore.
I have been storing them in a SharedPreferences file as follows (pseudo-code):
Key = "Song"+n
Value = _ID
When I need to retrieve the song IDs I just loop through the file for "Song"+0 to "Song"+n
This is working fine until I need to remove a song from the list. The obvious solution is to remove the relevant song and all songs after it in the list and then replace those songs with an index number one less than they previously had.
Something about this is smelling bad to me so my questions are:
- Is what I have described a fundamentally bad way of storing the list?
- If it is bad, what would be a better alternative?
- If using SharedPreferences in this way is reasonable then is my idea for removing items and reindexing the list a good idea?
- If it is not a good idea then again, what would be a better alternative?
Thank you in advance, Andrew