Save little information as setting in android (like first time that app is run)

Fcoder picture Fcoder · Mar 13, 2013 · Viewed 20.1k times · Source

I want to save a flag for recognizing that my app is run for the first time or not. For this simple job I don't want to create database..

Is there a simple option to do this? I want to save and read little pieces of information only.

Answer

Ajay S picture Ajay S · Mar 13, 2013

Use sharedPreference or files to save the data but better option is sharedPreference.

For Retrieving

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean silent = settings.getBoolean("silentMode", false);

For Saving

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("silentMode", true);
editor.commit();