Home

Awesome

Android SimpleSharedPreferences

Use SimpleSharedPreferences to avoid unnecessary code while writing and fetching from SharedPreferences

Build Status

Usage

Import any one *.jar into /libs

<pre>SimpleSharedPreferences.initialize(this); // from Application. SimpleSharedPreferences mPreferences = SimpleSharedPreferences.getInstance(); mPreferences.putString("STRING_KEY", "STRING_VALUE"); // Put String mPreferences.putInt("INTEGER_KEY", 50); // Put Int mPreferences.getString("STRING_KEY", "STRING_DEF_VALUE"); // Get String </pre>

##Error Throws ClassCastException when wrong key is passed

<pre>mPreferences.getString("INTEGER_KEY", "STRING_DEF_VALUE"); // Get String with Integer Key</pre> <pre> Error: ========================================================== ClassCastException : INTEGER_KEY's value is not a string ========================================================== </pre>

##Demo SimpleSharedPreferencesDemo.Java <br> Sample.apk

Other APIs

<pre> public int getAppOpenedCount() // Get the number of times app opened public boolean isLogEnabled() // default is false public void enableLog(boolean enableLog) // Update Log Status </pre>

###Note

Why?

<pre>// Old boring code SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor mEditor = mPreferences.edit(); mEditor.putString("STRING_KEY", "STRING_VALUE"); // mEditor mEditor.commit(); // mEditor ... ... ... mEditor.putInt("INTEGER_KEY", 50); // mEditor mEditor.commit(); // mEditor ... mPreferences.getString("STRING_KEY", "STRING_DEF_VALUE"); // mPreferences ... </pre>

imports

import com.venomvendor.library.SimpleSharedPreferences;

ProGuard

-keepclassmembers class * implements android.content.SharedPreferences.** { *; }
Author : VenomVendor

#License Copyright (C) 2016 VenomVendor info@VenomVendor.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.