https://github.com/pranavpandey/dynamic-preferences
Manage shared preferences on Android.
https://github.com/pranavpandey/dynamic-preferences
android library manage preferences shared
Last synced: about 1 year ago
JSON representation
Manage shared preferences on Android.
- Host: GitHub
- URL: https://github.com/pranavpandey/dynamic-preferences
- Owner: pranavpandey
- License: apache-2.0
- Created: 2019-10-12T02:41:39.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-07T14:31:12.000Z (over 2 years ago)
- Last Synced: 2024-04-14T05:42:56.381Z (about 2 years ago)
- Topics: android, library, manage, preferences, shared
- Language: Java
- Homepage: https://dynamic.pranavpandey.com
- Size: 978 KB
- Stars: 4
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README

# Dynamic Preferences
[](https://www.apache.org/licenses/LICENSE-2.0.html)
[](https://travis-ci.org/pranavpandey/dynamic-preferences)
[](https://search.maven.org/artifact/com.pranavpandey.android/dynamic-preferences)
**A library to manage shared preferences on Android 4.0 (API 14) and above.**
> [!IMPORTANT]
> It uses [AndroidX][androidx] so, first [migrate][androidx-migrate] your project to AndroidX.
Since v2.1.0, it is dependent on Java 8 due to the dependency on
[Dynamic Utils][dynamic-utils].
Since v2.3.1, it is targeting Java 17 to provide maximum compatibility.
Since v2.4.0, the minimum SDK is Android 4.4 (API 19) to comply with the latest policies.
---
## Contents
- [Installation](#installation)
- [Usage](#usage)
- [Initialize](#initialize)
- [Save](#save)
- [Load](#load)
- [Delete](#delete)
- [Dependency](#dependency)
- [License](#license)
---
## Installation
It can be installed by adding the following dependency to your `build.gradle` file:
```groovy
dependencies {
// For AndroidX enabled projects.
implementation 'com.pranavpandey.android:dynamic-preferences:2.4.0'
}
```
---
## Usage
It provides various methods to `save`, `load` and `delete` keys and preferences. Please read
below about the various supported operations.
> For a complete reference, please read the [documentation][documentation].
### Initialize
`DynamicPreferences` must be initialized once before accessing its methods.
```java
// Initialize with application context.
DynamicPreferences.initializeInstance(applicationContext);
```
After initializing, its various public methods can be accessed via getting the initialized
instance.
### Save
It supports the saving of `boolean`, `int`, `String` and `Set` value types into the
shared preferences.
```java
// 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);
```
### Load
It supports the retrieval of `boolean`, `int`, `String` and `Set` value types from the
shared preferences.
```java
// 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);
```
### Delete
It supports the deletion of a particular `key` or a complete shared preferences.
```java
// 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);
```
### Dependency
It depends on the [dynamic-utils][dynamic-utils] to perform various internal operations.
So, its functions can also be used to perform other useful operations.
---
## Author
Pranav Pandey
[](https://github.com/pranavpandey)
[](https://twitter.com/intent/follow?screen_name=pranavpandeydev)
[](https://paypal.me/pranavpandeydev)
---
## License
Copyright 2019-2024 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.
[androidx]: https://developer.android.com/jetpack/androidx
[androidx-migrate]: https://developer.android.com/jetpack/androidx/migrate
[documentation]: https://pranavpandey.github.io/dynamic-preferences
[dynamic-utils]: https://github.com/pranavpandey/dynamic-utils