SharedPref is deprecated in favor of Jetpack DataStore.
An android library for making SharedPreferences simple and easy!
implementation 'com.hitanshudhawan:shared-pref:1.0.0'
SharedPref sharedPref = new SharedPref(context);
// or
SharedPref sharedPref = new SharedPref(context, name);
// or
SharedPref sharedPref = new SharedPref(context, name, mode);
Default file name
will be packageName
of your project.
Default operating mode
will be MODE_PRIVATE
.
sharedPref.putString(key, value);
sharedPref.putInt(key, value);
sharedPref.putLong(key, value);
// and many more...
sharedPref.getString(key, defValue);
sharedPref.getInt(key, defValue);
sharedPref.getLong(key, defValue);
// and many more...
and that's it! No need for commit()
or apply()
.
Copyright (c) 2018 Hitanshu Dhawan
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.