Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 1.45 KB

README.md

File metadata and controls

33 lines (23 loc) · 1.45 KB

CrossProcessPreferences

SharedPreferences's MULTI_PROCESS_MODE has been deprecated in API 23 for being not so reliable. Thus if you want to use SharedPreferences in multiple processes then you can use this.

NuGet

CrossProcessPreferences NuGet

How to use it

It has an easy API that is similar to the one in SharedPreferences and works using a ContentProvider that must be registered in the AndroidManifest:

<application android:label="MyProject" android:icon="@mipmap/ic_launcher">
    <provider android:name="crossprocesspreferences.PreferenceProvider" android:authorities="crossprocesspreferences.PreferenceProvider" android:exported="false" />
</application>

Then you can use it like this:

var preferences = new CrossProcessSharedPreferences(this.Context, "myPreferencesName");
preferences.SetPrefString("myKey", "myValue");
var valueOfMyKey = preferences.GetPrefString("myKey", "defaultValue");
var isMyKeyStored = preferences.HasKey<string>("myKey");
// remove the key from the preferences
preferences.Remove("myKey");

It supports int, long, bool (also if they are nullable), string and DateTime (it will store it as UTC).

Roadmap

  • Add support for decimal, double