• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Store data after application life time

Leolicos

Member
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.
 
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.
 
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.
 
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.
 
Back
Top Bottom