QuickSPHelper使用详解-快速使用SharedPreferences

QuickSPHelper是什么东西呢,顾名思义就是快速使用SharedPreferences。

那此组件有什么特点:

无需配置,直接可使用,组件轻便

接下来我们看一下正常写法:

val sharedPreferences=getSharedPreferences("this is a name", Context.MODE_PRIVATE)
//存值
sharedPreferences.edit().putString("name","this is a name").putInt("age",1).commit()
//取值
sharedPreferences.getString("name","")
sharedPreferences.getInt("age",0)

存入与取值时需要调用相应的方法,这地方是可以优化的。

所以,请看下QuickSPHelper的写法

QuickSPHelper.putValue("name", "this is a name").putValue("age", 1)
QuickSPHelper.getValue("name","")
QuickSPHelper.getValue("age",0)

不需要实例,组件已经初始化好了,而且存入调用相同的方法,取值时也只有一个方法,统一管理,使用更省心。

使用方法很简单,end

推荐使用gradle接入

implementation 'org.quick.android:quick-component:latest.release'

统一初始化放在Application中:

QuickAndroid.init(this)

源码地址:https://github.com/SpringSmell/quick-component

好了,到这里就结束,好东西那当然要分享了,马上告诉小伙伴我发现了一个很酷的东西吧

QuickAndroid系列全家桶

猜你喜欢

转载自blog.csdn.net/Fy993912_chris/article/details/81698990