Store data after application life time


Last Updated:

  1. Leolicos

    Leolicos Well-Known Member This Topic's Starter

    Joined:
    Jun 16, 2010
    Messages:
    54
    Likes Received:
    0
    How do I store data on the device so even when the application terminates, the data can be loaded again once the application is run once again. Is it just as simple as storing a file on the SD card? Or is there some other way?

    Basically, I'm looking to offer the option to "trial" my program, but only for a certain number of times, so I want to keep track how many times my runs a certain feature even if the program isn't purchased and has a license. All I really need is to store a number of how many times it has run.
     

    Advertisement
  2. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    There are multiple ways depending on what you are trying to accomplish. You could use SharedPreferences, an SQLite database, or even a primitive file-type such as a text file or an XML file. It all really depends ont he app itself and what kind of data it needs.
     
  3. Leolicos

    Leolicos Well-Known Member This Topic's Starter

    Joined:
    Jun 16, 2010
    Messages:
    54
    Likes Received:
    0
    I would use the SharedPreference, since I know how to use it already, but how do I specify that I want this particular number to be store after the application is closed, or even when the phone is turned off.
     
  4. IanGClifton

    IanGClifton Well-Known Member

    Joined:
    Feb 7, 2010
    Messages:
    111
    Likes Received:
    19
    SharedPreferences are stored for you when you commit changes to them, so they can be retrieved even if the activity has died. That said, users are able to clear app data (at least in Froyo you can do so natively), which would probably clear your stored values, potentially allowing the user to keep using the trial version. I'm not sure how important that edge case is to you, but it's worth thinking about.
     

Share This Page

Loading...