Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Bilibili/xpref
A SharedPreferences' wrapper that truly supported sharing data across multi-process
https://github.com/Bilibili/xpref
android-library sharedpreferences
Last synced: 2 months ago
JSON representation
A SharedPreferences' wrapper that truly supported sharing data across multi-process
- Host: GitHub
- URL: https://github.com/Bilibili/xpref
- Owner: bilibili
- License: apache-2.0
- Created: 2017-12-25T17:43:41.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-27T15:40:22.000Z (about 7 years ago)
- Last Synced: 2024-11-11T12:19:39.985Z (2 months ago)
- Topics: android-library, sharedpreferences
- Language: Kotlin
- Homepage:
- Size: 159 KB
- Stars: 84
- Watchers: 6
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kotlin - xpref - Multiprocess sharedpreferences. (Libraries / Android)
README
Xpref
====A SharedPreferences' wrapper that truly supported sharing data across multi-process
### Principle
ContentProvider is designed to provide content between multiple applications that means it supported
sharing data between multi-process. Use it to wrap the SharedPreferences can make the latter truly
cross-process sharing data### Usage
Add dependency to your gradle script:
```groovy
dependencies {
implementation 'com.bilibili.lib:x-pref:1.2'
}
```Note that this library is written with kotlin 1.2.10.
1. Gets the default SharedPreferences which is typically used in the Settings of an APP.
```kotlin
Xpref.getDefaultSharedPreferences(context)
```2. Gets a SharedPreferences with specific named.
```kotlin
val name = "awesome"
Xpref.getSharedPreferences(context, name)
```3. Extension in Kotlin.
You can declare extension functions in somewhere on your need for better convenience usage like following:
```kotlin
fun T.xpref() = Xpref.getDefaultSharedPreferences(this)fun T.xpref(name: String) = Xpref.getSharedPreferences(this, name)
```
```kotlin
// in Activity
class AnActivity : Activity() {
private fun getPreferences() = this.xpref("awesome")
}// in Service
class AService : Service() {
private fun getPreferences() = this.xpref("awesome")
}
```The other usage is the same as normal SharedPreferences.
Have fun!