Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Dicky Moore
432 PointsAdding a settings page and saving the settings in an android app
Hello
Can anyone point me towards a resource which will walk me through how to add a settings page to my Android app and how to ensure that those settings are saved on exit and loaded on startup?
I've had a search of the site and can't seem to find anything that specifically relates to Android. Please forgive me if I haven't conducted my search thoroughly enough.
Thanks in advance
3 Answers
Ernest Grzybowski
Treehouse Project ReviewerThere are two main ways to save data in an Android application that is persistent. One way is through SharedPreferences and another is in SQLite database's. There is actually a tutorial on d.android.com that goes through this.
For saving things such as username and other settings, I recommend SharedPreferences. It uses a "key value" method to save things. Extremely simple to implement in a few lines.
Here is the link: http://developer.android.com/training/basics/data-storage/index.html
And just click "Get Started" in the upper right.
Ben Jakuben
Treehouse TeacherAs @Ernest pointed out, SharedPreferences is probably what you're looking for. Note that it's not just limited to "preferences"--that's just how it's named. It's a simple store for persistent data.
I'm actually half-way through recording a Quick Tip on how to use SharedPreferences. Until then, check out this StackOverflow question that includes links to some short videos that talk about using SharedPreferences.
Dicky Moore
432 PointsThat is incredibly useful. Thanks so much, guys!