Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Storing/Retrieving Data with Shared Preferences

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Storing/Retrieving Data with Shared Preferences

    I have an application with 7 separate views. In each of those views there is an option to answer a 'yes' or 'no.' We are trying to save these 'yes' or 'no' values using shared preferences. Then, we want to have a new view/layout and be able to call those values from shared preferences. How do I go about doing that? My group and I have tried several different ways but cannot seem to get it to work. I know I don't have any code posted but it's because my code is just in bits and pieces. Thanks.


  2. #2
    Forum VIP
    Join Date
    Jun 2011
    Posts
    377
    My Mood
    Busy
    Thanks
    49
    Thanked 111 Times in 94 Posts
    Blog Entries
    5

    Default Re: Storing/Retrieving Data with Shared Preferences

    Probably should have been posted to the Android development forum but oh well.

    If you just use getSharedPreferences() on a component you are creating an private shared preference only available to that activity. Use a PreferenceManager to get the default shared preference file instead.

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
     
    // Add a key/value pair
    SharedPreferences.Editor editor = prefs.edit();
    boolean myValue = true;
    editor.putBoolean("myKey", myValue);
    editor.commit();
     
    // Retrieve a value
    prefs.getBoolean("myKey", true);

Similar Threads

  1. Java Shared Data Toolkit
    By cjchanni in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 21st, 2013, 09:09 AM
  2. Setting a spinner from Shared Preferences
    By jdubicki in forum Android Development
    Replies: 0
    Last Post: September 26th, 2012, 08:56 AM
  3. Retrieving data from backend
    By chaitime in forum JDBC & Databases
    Replies: 5
    Last Post: April 29th, 2012, 03:28 PM
  4. Thread/Mutex/Shared data buffer
    By m000 in forum Threads
    Replies: 0
    Last Post: January 5th, 2011, 10:18 PM
  5. problem in retrieving data via RMS
    By solaleh in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: August 30th, 2009, 06:46 AM

Tags for this Thread