public interface OnSecurePreferenceChangeListener
OnSecurePreferenceChangeListener.DerivedKeyComparison instance in order to make it possible compare the changed key against
actual key constants (instead of the derivedKeys that the library uses)
public class SampleActivity extends AppCompatActivity {
private final String KEY_TOKEN = "token";
private final OnSecurePreferenceChangeListener onSecurePreferenceChangeListener = (sharedPreferences, comparison) -> {
if (comparison.isDerivedKeyEqualTo(KEY_TOKEN)) {
String newToken = sharedPreferences.getString(KEY_TOKEN, null);
onTokenUpdated(newToken);
}
};
private void onTokenUpdated(String newToken) {
// Do whatever is required when underlying token has been updated
}
@Overrides
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ... initialize encrypted preferences ...
encryptedPreferences.registerOnSecurePreferenceChangeListener(onSecurePreferenceChangeListener);
}
}
| Modifier and Type | Interface and Description |
|---|---|
static interface |
OnSecurePreferenceChangeListener.DerivedKeyComparison
Allows client side
OnSecurePreferenceChangeListener to check if the changed key is the key of interest. |
| Modifier and Type | Method and Description |
|---|---|
void |
onSecurePreferenceChanged(android.content.SharedPreferences sharedPreferences,
OnSecurePreferenceChangeListener.DerivedKeyComparison comparison)
Variation of the regular
SharedPreferences.OnSharedPreferenceChangeListener.onSharedPreferenceChanged(SharedPreferences, String) that
provides a OnSecurePreferenceChangeListener.DerivedKeyComparison to allow client side react only to a specific changed key |
void onSecurePreferenceChanged(android.content.SharedPreferences sharedPreferences,
OnSecurePreferenceChangeListener.DerivedKeyComparison comparison)
SharedPreferences.OnSharedPreferenceChangeListener.onSharedPreferenceChanged(SharedPreferences, String) that
provides a OnSecurePreferenceChangeListener.DerivedKeyComparison to allow client side react only to a specific changed keysharedPreferences - the shared preferences instancecomparison - utility to check equivalence between plain keys and derived keys