Giter Club home page Giter Club logo

xpref's Introduction

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:

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.
Xpref.getDefaultSharedPreferences(context)
  1. Gets a SharedPreferences with specific named.
val name = "awesome"
Xpref.getSharedPreferences(context, name)
  1. Extension in Kotlin.

You can declare extension functions in somewhere on your need for better convenience usage like following:

fun <T: ContextWrapper> T.xpref() = Xpref.getDefaultSharedPreferences(this)

fun <T: ContextWrapper> T.xpref(name: String) = Xpref.getSharedPreferences(this, name)
// 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!

xpref's People

Contributors

yrom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.