1. Check out our companion app, Forums for Android! Download from Google Play

Simple data

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

  1. rick99gtp

    rick99gtp Member
    Thread Starter
    15

    Aug 6, 2010
    12
    0
    15
    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
     

    Advertisement

  2. blundell

    blundell Well-Known Member
    38

    Apr 23, 2010
    125
    17
    38
    Software Engineer
    UK
  3. rick99gtp

    rick99gtp Member
    Thread Starter
    15

    Aug 6, 2010
    12
    0
    15
    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
    38

    Apr 23, 2010
    125
    17
    38
    Software Engineer
    UK
    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 Member
    Thread Starter
    15

    Aug 6, 2010
    12
    0
    15
    Ah, ha! You're a genius! ;)

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

Share This Page

Loading...