Name: xpref
Owner: bilibili
Description: A SharedPreferences' wrapper that truly supported sharing data across multi-process
Created: 2017-12-25 17:43:41.0
Updated: 2018-05-23 07:36:36.0
Pushed: 2017-12-27 15:40:22.0
Size: 163
Language: Kotlin
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A SharedPreferences' wrapper that truly supported sharing data across multi-process
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
Add dependency to your gradle script:
ndencies {
implementation 'com.bilibili.lib:x-pref:1.2'
Note that this library is written with kotlin 1.2.10.
f.getDefaultSharedPreferences(context)
name = "awesome"
f.getSharedPreferences(context, name)
You can declare extension functions in somewhere on your need for better convenience usage like following:
<T: ContextWrapper> T.xpref() = Xpref.getDefaultSharedPreferences(this)
<T: ContextWrapper> T.xpref(name: String) = Xpref.getSharedPreferences(this, name)
n Activity
s AnActivity : Activity() {
private fun getPreferences() = this.xpref("awesome")
n Service
s AService : Service() {
private fun getPreferences() = this.xpref("awesome")
The other usage is the same as normal SharedPreferences.
Have fun!