1. Download our Official Android App: Forums for Android!

Apps Simple data

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

  1. rick99gtp

    rick99gtp Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    12
    Joined:
    Aug 6, 2010

    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
    Rank:
    None
    Points:
    38
    Posts:
    124
    Joined:
    Apr 23, 2010

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

    rick99gtp Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    12
    Joined:
    Aug 6, 2010

    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
    Rank:
    None
    Points:
    38
    Posts:
    124
    Joined:
    Apr 23, 2010

    Apr 23, 2010
    124
    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 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    12
    Joined:
    Aug 6, 2010

    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...