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

Android

initializing the mSharedPreferences variable w/ the appropriate method from PreferenceManager. context as the parameter

Key-Value Saving with SharedPreferences

Storing a value in shared preferences challenge: http://teamtreehouse.com/library/android-data-persistence/keyvalue-saving-with-sharedpreferences/storing-a-value-in-sharedpreferences

I ended up using this stackoverflow thread to find the answer

to part 1 of the challenge: http://stackoverflow.com/questions/14179060/preference-manager-and-shared-preferences

SharedPreferences mSharedPreferences;
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences( context );
SharedPreferences.Editor editor;

From the code in this stackoverflow thread: http://stackoverflow.com/questions/9471406/choosing-a-layout-error

I got this code:

editor = mSharedPreferences.edit();

Then for the rest of this code this forum post solved the issue of how to use commit properly

(using "fluent interface" "method chaining"

who knew?) :

https://teamtreehouse.com/forum/meaningoflife-answer

SharedPreferences.Editor editableSharedPreferences = mSharedPreferences
  .edit()
  .putInt("MeaningOfLife",42);
  editableSharedPreferences.commit();

If only the video transcripts where just a little more helpful

I wouldn't have to use my general internet research skills as much...

This helped me a lot with the challenge....thanks for posting this

Kien Doan
Kien Doan
17,538 Points

This too works well.

SharedPreferences mSharedPreferences;
SharedPreferences.Editor editor;

mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
editor = mSharedPreferences.edit();
editor.putInt("MeaningOfLife", 42);
editor.commit();