I am using the following code to check the application is first time running or not
SharedPreferences pref = getPreferences(MODE_PRIVATE);
if (!pref.contains(KEY
The following works for me:
private static String KEY_FIRST_RUN = "";
private SharedPreferences sharedPreferences;
private SharedPreferences.Editor editor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sharedPreferences = getPreferences(MODE_PRIVATE);
if (!sharedPreferences.contains("KEY_FIRST_RUN")) {
KEY_FIRST_RUN = "something";
Log.d("First", "First run!");
} else {
Log.d("Second...", "Second run...!");
}
editor = sharedPreferences.edit();
editor.putString("KEY_FIRST_RUN", KEY_FIRST_RUN);
editor.commit();
}