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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:13:07+00:00 2026-05-24T01:13:07+00:00

I want to store some basic data like players_name,levels_completed,fastest_speed,fastest_time and bring it up each

  • 0

I want to store some basic data like players_name,levels_completed,fastest_speed,fastest_time and bring it up each time the player starts a silly little game I am making… which is the perffered method to do this?

Sharedprefs or internal storage?

I am at http://developer.android.com/guide/topics/data/data-storage.html
and have just gotten confused as to which to use as both look good and easy enough to do.

Advise?

Thanks!

  • 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-24T01:13:08+00:00Added an answer on May 24, 2026 at 1:13 am

    This is pretty much taken from one of the Facebook sdks examples (it allows you to save the FB session so the user doesn’t have to login each time)… I’ll modify it a bit for you though

    public class SessionStore {
    
    private static final String PLAYER_NAME = "player_name";
    private static final String LEVELS_COMPLETED = "levels_completed";
    private static final String HIGH_SCORE = "high_score";
    
    private static final String KEY = "player_session";
    
    int highScore;
    int levelsCompleted;
    String pName;
    
    public static boolean saveSession(Context context, String player_name, int levels_completed, int high_score) {
        Editor editor =
            context.getSharedPreferences(KEY + player_name, Context.MODE_PRIVATE).edit();
        editor.putString(PLAYER_NAME,player_name);
        editor.putInt(LEVELS_COMPLETED, levels_completed);
        editor.putInt(HIGH_SCORE,high_score);
    
        return editor.commit();
    }
    
    public static void restoreSession(Context context, String player_name) {
        SharedPreferences savedSession =
            context.getSharedPreferences(KEY + player_name, Context.MODE_PRIVATE);
        highScore = savedSession.getInt(HIGH_SCORE,0);
        levelsCompleted = savedSession.getInt(LEVELS_COMPLETED,0);
        pName = savedSession.getString(PLAYER_NAME,"NO_NAME!");
    
    }
    
    public String getName()
    {
          return pName;
    }
    

    }

    I think you get the basic idea…

    some points: I use “KEY + player_name” in case different players play on the same phone (if it was static you would overwrite the data of one player with anothers data).

    Also, when you do pName = savedSession.getString(PLAYER_NAME,"NO_NAME!"); if nothing exists in the shared preferences it defaults to the value “NO_NAME!” and likewise for the getInts (which in this case I have them default to 0)

    in the program you would do SessionStore.saveSession("Alex",50000,50000); to save the session, etc. Hope this gives a good gist of how to use it… Also keep in mind I’m an android newb – this works great for me but I’m no expert 😀

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

Sidebar

Related Questions

I want to temporary store some mapping data. The mapping is one to one.
I want to use Context.Items to store some info of a User Control like:
I have some data that I want to store somewhere in my Rails app
I want to store the average values of some data that is occasionally generated
I want to store some data into byte arrays in Java. Basically just numbers
I want to use session object in my web app.I want to store some
I'm working on a project and I want to store some easily enumerated information
Is this possible? Situation is that I want to store some XML in my
I store some dates in my NSMutableArray, I want to retrieve them and change
I want to create an ini file to store some settings for my application.

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.