2

I'm working on a live wallpaper that is configured using a preferences screen. I use shared preferences to store things like color, speed and movement of the wallpaper. As I've got a lot of settings, I'd like users to be able to:

  • save all the current preferences under a profile, where the profile is assign a name by the user.
  • the user can then select a profile by name from a list and have all their settings restored.
  • the user can also delete profiles.

Can anyone recommend a nice way of doing this?

One idea I had was to save all the current preferences to an XML file and selecting a profile would just load the file and set the shared preferences based on this. However, if I had 20 or so profiles, I would need to inspect all the files to produce a list of profile names (as I'd have to store the profile name in each file) which seem inefficient.

drjr
  • 21
  • 1

1 Answers1

0

I implemented a profile system in one of my apps with the help of an SQLiteDatabase (basics are explained in the notepad tutorial). You only need one table to store profile name/id, and all of the settings you want.

  • save each profile as a new record in your table, with an appropriate name field
  • retrieve all records and display the list of names when you want to user to be able to select a profile (e.g. SELECT * FROM Profile)
  • delete a profile in your system by deleting the corresponding record (e.g. DELETE FROM Profile WHERE name='john')

I also saved the name/identifier of the current profile using SharedPreferences so that my system had an easy way to know which profile was currently/most recently active, outside of the context of profile loading.

antonyt
  • 21,863
  • 9
  • 71
  • 70
  • Why did you pick sql over, save, an XML file format? The latter seems more flexible to me and e.g. makes it easy for users to exchange profile files. – drjr Jan 12 '11 at 09:48
  • My profile data was heavily linked to other areas of my system and I felt more comfortable implementing it with a SQLite db. I think SQLite would offer better support for scalability and data manipulation/querying. For simple data storage, I think XML could be suitable here. However, it is hard to be sure that your use cases for the data will stay simple forever... Using XML for profile exchange is still a good idea. http://stackoverflow.com/questions/201568/when-would-i-use-xml-instead-of-sql – antonyt Jan 12 '11 at 11:36