1. Are you ready for the Galaxy S20? Here is everything we know so far!

Simple data

Discussion in 'Android Development' started by rick99gtp, Aug 9, 2010.

  1. rick99gtp

    rick99gtp Newbie
    Thread Starter

    When searching for how to store small pieces of information for my app I run into this a lot, "Unless your application deals only with simple data, you need a database system to store your structured data".

    So, how do I handle simple data? With FileInputStream? Where is this hard to find data/data folder?

    Anyone have information to share?

    Thanks

    ~Rick
     


  2. blundell

    blundell Well-Known Member

  3. rick99gtp

    rick99gtp Newbie
    Thread Starter

    Either I don't understand how I would utilize the Preferences you recommended or I didn't explain myself very well. :)

    I'd like to store the user's best score in a data file and be able to read it back in and display it on screen when needed. Can I do this with Preferences?
     
  4. blundell

    blundell Well-Known Member

    Yes you can :-D!
    SAVE:
    Code (Text):
    1.  
    2. SharedPreferences.Editor editor = getPreferences(0).edit();
    3. editor.putInt("highScore", 39999);
    4. editor.commit();
    5.  
    RETREIVE:
    Code (Text):
    1.  
    2. SharedPreferences prefs = getPreferences(0);
    3.  int highscore = prefs.getInt("highScore", -1);
    4.  
     
    rick99gtp likes this.
  5. rick99gtp

    rick99gtp Newbie
    Thread Starter

    Ah, ha! You're a genius! ;)

    I wondered if there was a way to save game state in this fashion. Thanks so much!
     
Loading...

Share This Page

Loading...