Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6823277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:45:50+00:00 2026-05-26T21:45:50+00:00

EDIT: OK It turns out this code was working (more or less) I’d left

  • 0

EDIT:
OK It turns out this code was working (more or less) I’d left in a line that reset the booleans I was trying to change. Thanks everyone for the help though.

Having trouble using SharedPreferences to read in saved array data when my app starts.
My _dPad Boolean and my _FreePlay Integer loads, saves and passes to and from my _renderer without any problems.

The trouble starts when I try and use some arrays
easteregg[] only has 2 entries right now so obviously I could just just turn them into separate variables but I wish to add more arras of longer length so this makes a convenient test example.

I’ve noted on the code what appears to happen (the easteregg[] settings just doesn’t appear to have changed)

to read data:

    // Read saved preferences    
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    _renderer._dPad = prefs.getBoolean("_dPad", false);                // * works ok *
    _renderer._FreePlay = prefs.getInt("_FreePlay", 1);                // * works ok *
    _renderer.easteregg[0] = prefs.getBoolean("easteregg[0]", false ); // * not working
    _renderer.easteregg[1] = true;                        // * even this is not working

    setRenderer(_renderer);

to write data:

    public void onDetachedFromWindow() {
    super.onDetachedFromWindow();

    // As good a time as any to save current config
    save = false ; // don't commit if nothing changed.

    SharedPreferences prefs =                       
    PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();

    if (_renderer._dPad != prefs.getBoolean("_dPad",false)){ save = true ;
    editor.putBoolean("_dPad", _renderer._dPad);}

    if (_renderer._FreePlay != prefs.getInt("_FreePlay",1)){ save = true ;
    editor.putInt("_FreePlay", _renderer._FreePlay);}

    editor.putBoolean("easteregg[0]", _renderer.easteregg[0]);

    editor.putBoolean("easteregg[1]", _renderer.easteregg[1]);

    if (save == true){editor.commit();}

}

And in the .renderer class

    // START SAVE DATA
    public boolean _dPad ; // false no Virtual Pad     *Works Fine*
    public int _FreePlay ;  // 1 = no free play        *Works Fine*
    public boolean[] easteregg = new boolean[2];       *Values don't load or save*
    //public boolean easteregg[]; // tried this first  *CAUSES CRASH*
    // END SAVE DATA

Do I have to convert the arrays to strings? I don’t get how to change them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:45:50+00:00Added an answer on May 26, 2026 at 9:45 pm

    I put your code into a quick activity, creating just the shell of the renderer class as you have above and found that your save boolean is false, so it never commits the preferences.

    I forced the save to true, and played around with it and everything worked fine from there.

    I’d recommend adding checks to the easter eggs the same as you have for any other preference; test to see if the current value is the same as the saved value, and if not, set the save flag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: Originally I had a simple form Ajax script that wasn't working, turns out
Edit: It turns out I missed something obvious, but I'm going to leave the
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
Edit! Turns out I had just got too many apostrophes going on when calling
I am working on a java program that is essentially a chat room. This
I've been trying to troubleshoot this, but can't find a good function that will
I'm working on some code that will DD a block device over SSH, and
Edit: This question was written in 2008, which was like 3 internet ages ago.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.