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 7050219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:07:00+00:00 2026-05-28T03:07:00+00:00

I am creating an app with several activities. SharedPreferences are read in multiple activities.

  • 0

I am creating an app with several activities. SharedPreferences are read in multiple activities.

I have found that when I update a single variable in one of the SharedPreferences files, all of the variables in that file take on the value assigned.

Is there a general reason why this might occur? If not, I can post code.

THE FOLLOWING CODE IS USED TO WRITE AND READ THE VALUES (anything in all caps is a unique integer constant)

public void LevelUp(int gameType) {
    step++;
    SharedPreferences settings = getSharedPreferences("Steps", 0);
    SharedPreferences.Editor editor = settings.edit();
    switch (gameType) {
        case NUMBERS_SPEED:   editor.putInt("NUMBERS_SPEED",   step);
        case NUMBERS_BINARY:  editor.putInt("NUMBERS_BINARY",  step);
        case NUMBERS_SPOKEN:  editor.putInt("NUMBERS_SPOKEN",  step);
        case LISTS_WORDS:     editor.putInt("LISTS_WORDS",     step);
        case LISTS_EVENTS:    editor.putInt("LISTS_EVENTS",    step);
        case SHAPES_FACES:    editor.putInt("SHAPES_FACES",    step);
        case SHAPES_ABSTRACT: editor.putInt("SHAPES_ABSTRACT", step);
        case CARDS_SPEED:     editor.putInt("CARDS_SPEED",     step);
    }
    editor.commit();        
}

public int getStep(int gameType) {
    SharedPreferences settings = getSharedPreferences("Steps", 0);
    switch (gameType) {
        case NUMBERS_SPEED:   return settings.getInt("NUMBERS_SPEED", 1);
        case NUMBERS_BINARY:  return settings.getInt("NUMBERS_BINARY", 1);
        case NUMBERS_SPOKEN:  return settings.getInt("NUMBERS_SPOKEN", 1);
        case LISTS_WORDS:     return settings.getInt("LISTS_WORDS", 1);
        case LISTS_EVENTS:    return settings.getInt("LISTS_EVENTS", 1);
        case SHAPES_FACES:    return settings.getInt("SHAPES_FACES", 1);
        case SHAPES_ABSTRACT: return settings.getInt("SHAPES_ABSTRACT", 1);
        case CARDS_SPEED:     return settings.getInt("CARDS_SPEED", 1);
        default: return -1;
    }
}

THE FOLLOWING CODE RESIDES IN A DIFFERENT ACTIVITY:

SharedPreferences settings = getSharedPreferences("Steps", 0);
step = settings.getInt("NUMBERS_SPOKEN", 1);
  • 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-28T03:07:00+00:00Added an answer on May 28, 2026 at 3:07 am

    You need breaks between your case statements

    switch (gameType) {
        case NUMBERS_SPEED:   editor.putInt("NUMBERS_SPEED",   step);
        break;
        case NUMBERS_BINARY:  editor.putInt("NUMBERS_BINARY",  step);
        break;
    

    Otherwise it will go through every case statement which is why they are all getting assigned that value

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

Sidebar

Related Questions

I'm creating and app that will rely on a database, and I have all
I'm creating an app that will import products from several XML feeds. In the
I am creating an iPad app that has several pictures ( UIImageViews ) in
I am creating a Host SL app that will serve up several Plugins Each
We have already built a rails app that has several users and an image
I'm creating a login form that's loaded from a nib. I have several NSTextFields,
We are creating an enterprise android app that would be installed on several mobiles
I'm creating an app where within a UIView subclass I have several UIImageView 's
I have a C# app that works on several machines, but for some reason
I have a several activities in my app. The main activity (activity1) extends ActivityGroup

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.