You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
746 B
Kotlin
30 lines
746 B
Kotlin
package com.yinuo.commonlib.utils
|
|
|
|
import android.annotation.SuppressLint
|
|
import android.content.Context
|
|
import android.content.SharedPreferences
|
|
|
|
|
|
/**
|
|
* sharedPreference管理类
|
|
*/
|
|
object SpManager {
|
|
const val HAS_INIT = "has_init"
|
|
private var sp: SharedPreferences? = null
|
|
private var editor: SharedPreferences.Editor? = null
|
|
|
|
@SuppressLint("CommitPrefEdits")
|
|
fun init(context: Context, name: String, mod: Int) {
|
|
sp = context.getSharedPreferences(name, mod)
|
|
editor = sp!!.edit()
|
|
}
|
|
|
|
fun putBoolean(key: String, boolean: Boolean) {
|
|
editor!!.putBoolean(key, boolean)
|
|
editor!!.apply()
|
|
}
|
|
|
|
fun getBoolean(key: String): Boolean {
|
|
return sp!!.getBoolean(key, false)
|
|
}
|
|
} |