I recommend for you the SharedPreferences. This is an in Android simple class, that stores you data in Key-Value sets.
Here is the code:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
This initialize your SharedPreferences. If you want to write/change a value, do this:
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("KEY_TO_VALUE", 123);
editor.commit();
You also can put in there other types of values, but than you need to call putString
or putBoolean
or even other types.
To read the value do this:
int a = prefs.getInt("KEY_TO_VALUE", 0);
This code need like always your parameter your Key and a the second parameter a default value.
Another tip for you is, that if you want to use this in a normal app with an easy UI there is something called PreferenceScreen.
1
solved Where to store app data?