SharedPreferences Sample

Posted on July 7, 2011
import android.content.SharedPreferences;
SharedPreferences settings = getSharedPreferences(GAME_PREFERENCES, MODE_PRIVATE);
String lastLaunch = "First launch";
if (settings.contains("lastLaunch") == true)
	lastLaunch = settings.getString("lastLaunch", lastLaunch);
String currentTime = (String) DateFormat.format("yyyy-MM-dd hh:mm:ss", new Date());
SharedPreferences.Editor prefEditor = settings.edit();
prefEditor.putString("lastLaunch", currentTime);
prefEditor.commit();

Categories: Android Code Snippets


Leave a Reply

Switch to our desktop site