-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d6f8ce
commit f2b218e
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Harmony Preferences | ||
[![CircleCI](https://circleci.com/gh/pablobaxter/HarmonyPreferences/tree/master.svg?style=shield)](https://circleci.com/gh/pablobaxter/HarmonyPreferences/tree/master) ![GitHub](https://img.shields.io/github/license/pablobaxter/HarmonyPreferences) [ ![Download](https://api.bintray.com/packages/soaboz/Harmony/com.frybits.harmonyprefs/images/download.svg?version=0.0.1) ](https://bintray.com/soaboz/Harmony/com.frybits.harmonyprefs/0.0.1/link) | ||
|
||
Working on multiprocess Android apps is a complex undertaking. One of the biggest challenges is managing shared data between the multiple processes. Most solutions rely on one process to be available for another to read the data, which can be quite slow and could potentially lead to ANRs. | ||
|
||
Harmony is a thread-safe, process-safe, full [`SharedPreferences`](https://developer.android.com/reference/android/content/SharedPreferences) implementation. It can be used in place of [`SharedPreferences`](https://developer.android.com/reference/android/content/SharedPreferences) everwhere. | ||
|
||
## Features | ||
- Built to support multiprocess apps | ||
- Full [`SharedPreferences`](https://developer.android.com/reference/android/content/SharedPreferences) implementation | ||
- [`OnSharedPreferenceChangeListener`](https://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener) emits changes made by other processes | ||
- No native code (NDK) usage and uses no [`ContentProvider`](https://developer.android.com/reference/android/content/ContentProvider), [`Service`](https://developer.android.com/reference/android/app/Service), [`BroadcastReceiver`](https://developer.android.com/reference/android/content/BroadcastReceiver), or [AIDL](https://developer.android.com/guide/components/aidl) | ||
- Built-in failed-write recovery similar to the default [`SharedPreferences`](https://developer.android.com/reference/android/content/SharedPreferences) | ||
- Min Android API: 11 | ||
|
||
## Download | ||
### Gradle | ||
``` | ||
implementation 'com.frybits.harmonyprefs:harmony:0.1' | ||
``` | ||
|
||
## Usage | ||
|
||
### Creating Harmony SharedPreferences | ||
#### Kotlin | ||
```kotlin | ||
// Getting Harmony SharedPreferences | ||
val prefs: SharedPreferences = context.getHarmonySharedPreferences("PREF_NAME") | ||
``` | ||
|
||
#### Java | ||
```java | ||
// Getting Harmony SharedPreferences | ||
SharedPreferences prefs = Harmony.getSharedPreferences(context, "PREF_NAME") | ||
``` | ||
|
||
Once you have this `SharedPreferences` object, it can be used just like any other `SharedPreferences`. The main difference with `Harmony` is that any changes made to `"PREF_NAME"` using `apply()` or `commit()` is reflected across all processes. | ||
|
||
## Change Log | ||
### Version 0.0.1 / 2020-05-15 | ||
- Initial release! | ||
|
||
## License | ||
``` | ||
MIT License | ||
Copyright (c) 2020 Pablo Baxter | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters