A library to manage shared preferences on Android 4.0 (API 14) and above devices.
It uses AndroidX so, first migrate your project to AndroidX.
It can be installed by adding the following dependency to your build.gradle
file:
dependencies {
// For AndroidX enabled projects.
implementation 'com.pranavpandey.android:dynamic-preferences:1.3.1'
}
Please read below about the various supported operations.
For complete reference, please read the documentation.
DynamicPreferences
must be initialized once before accessing its methods.
// Initialize with application context.
DynamicPreferences.initializeInstance(applicationContext);
After initializing, its various public methods can be accessed via getting the initialized instance.
It supports the saving of boolean
, int
, String
and Set<String>
value types into the
shared preferences.
// Save a value in the default shared preferences.
DynamicPreferences.getInstance().save(key, value);
// Save a value in the supplied shared preferences.
DynamicPreferences.getInstance().save(preferences, key, value);
It supports the retrieval of boolean
, int
, String
and Set<String>
value types from the
shared preferences.
// Retrieve a value from the default shared preferences.
DynamicPreferences.getInstance().load(key, defaultValue);
// Retrieve a value from the supplied shared preferences.
DynamicPreferences.getInstance().save(preferences, key, defaultValue);
It supports the deletion of a particular key
or a complete shared preferences.
// Remove a key from the default shared preferences.
DynamicPreferences.getInstance().delete(key);
// Remove a key from the supplied shared preferences.
DynamicPreferences.getInstance().delete(preferences, key);
// Delete a shared preferences.
DynamicPreferences.getInstance().deleteSharedPreference(preferences);
It depends on the dynamic-utils to perform various internal operations. So, its functions can also be used to perform other useful operations.
Pranav Pandey
Copyright 2019-2021 Pranav Pandey
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.