What I understood about context.MODE_PRIVATE
or MODE_READABLE, WRITABLE
is that those functions make files for sharedprefrences.
I am wondering what the difference is between context.getSharedPreferences(KEY, Context.MODE_PRIVATE)
and getSharedPreferences(KEY, 0);
.
getSharedPreferences
retrieves its preferences from a xml folder as far as I know. And Context.MODE_PRIVATE
stores its files. And why use context.getSharedPreferences(KEY, Context.MODE_PRIVATE)
if both getSharedPreferences(KEY, 0)
and context.getSharedPreferences(KEY, Context.MODE_PRIVATE)
makes files.
Below is part of the Facebook API where I noticed Context.MODE_PRIVATE
.
public static boolean save(Facebook session, Context context) {
Editor editor =
context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
editor.putString(TOKEN, session.getAccessToken());
editor.putLong(EXPIRES, session.getAccessExpires());
return editor.commit();
}
public static boolean restore(Facebook session, Context context) {
SharedPreferences savedSession =
context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
session.setAccessToken(savedSession.getString(TOKEN, null));
session.setAccessExpires(savedSession.getLong(EXPIRES, 0));
return session.isSessionValid();
}