- 22 November, 2019
- 1 Min read
Dynamic Preferences
Manage shared preferences on Android.
A library to manage shared preferences on Android 4.0 (API 14) and above devices.
Background
I have various apps on Google Play and sometimes it is required to access shared preferences from anywhere within an app. So, I wrote this library to provide that functionality easily and quickly. Please read below to know more about its usage.
Usage
It is based on the singleton approach to manage shared preferences within an app. This library is fully commented so I am highlighting some of the features below.
Please follow and keep exploring the GitHub repository to find out more hidden features.
Initialize
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.
Save
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);Load
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);Delete
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);Dependency
It depends on the dynamic-utils to perform various internal operations. So, its functions can also be used to perform other useful operations.
Installation
Please follow the GitHub repository for the installation guide. I hope it will help you in your projects and please ask questions or share your feedback in the comments section to make it better.
Related Posts
- 26 June, 2017
Dynamic Utils
- Pranav Pandey
- 7 Min read
Utility functions to perform dynamic operations on Android.
- 18 March, 2019
Create bitmap from a view
- Pranav Pandey
- 3 Min read
Create a bitmap from the view on Android.
- 06 November, 2019
- $0/m
Pokémon Sidekick
- Pranav Pandey
- 3 Min read
A live wallpaper port from the Google Pixel 4 devices.
- 09 November, 2019
Everyday | Calendar Widget
- Pranav Pandey
- 3 Min read
The missing link in between your calendar and widget on Android.
- 08 November, 2019
Rotation | Orientation Manager
- Pranav Pandey
- 5 Min read
A tool to manage the device orientation on Android.
- 15 November, 2019
Dynamic Dialogs
- Pranav Pandey
- 4 Min read
Display improved dialogs and dialog fragments on Android.
- 13 December, 2019
Palettes | Theme Manager
- Pranav Pandey
- 2 Min read
A universal manager for apps supporting the dynamic theme on Android.
- 13 August, 2021
Zerocros | Tic-tac-toe Game
- Pranav Pandey
- 1 Min read
A simple yet customizable tic-tac-toe game for Android.
- 15 January, 2022
Barquode | Matrix Manager
- Pranav Pandey
- 3 Min read
A tool to create, capture and manage matrix codes on Android.
- 05 December, 2022
- $5/m
Dynamic Ads
- Pranav Pandey
- 10 Min read
Show GDPR-compliant ads via Google AdMob on Android.
- 04 February, 2024
- $0/m
Dynamic Theme
- Pranav Pandey
- 19 Min read