You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because sometimes we would like to encrypt SharedPreferences' data.
Usage
From SharedPreferences documented example:
publicclassCalcextendsActivity {
publicstaticfinalStringPREFS_NAME = "MyPrefsFile";
@OverrideprotectedvoidonCreate(Bundlestate){
super.onCreate(state);
. . .
// Restore preferencesSecureSharedPreferencessettings = newSecureSharedPreferences(this);
booleansilent = settings.getBoolean("silentMode", false);
setSilent(silent);
}
@OverrideprotectedvoidonStop(){
super.onStop();
// We need an Editor object to make preference changes.// All objects are from android.context.ContextSecureSharedPreferencessettings = newSecureSharedPreferences(this);
SecureSharedPreferences.Editoreditor = settings.edit();
editor.putBoolean("silentMode", mSilentMode);
// Commit the edits!// editor.commit(); // Autocommit is on by default ;)
}
}
API
All SharedPreferences methods were implemented except for SharedPreferences.getAll(). I'm still working on it.
You can save an Object (implements Serializable) and retrieve it later.
As it uses an bytearray version of the Serialized object, you have to pay attention when you update the object's Class because getSerializable method can return 'null' if you change some Class field.