AndroidUtilCode icon indicating copy to clipboard operation
AndroidUtilCode copied to clipboard

SPUtils 取不出值

Open morefreeliang opened this issue 3 years ago • 0 comments

我在DialogFragment中存值 :SPUtils.getInstance().put(Keys.UpdateTime, time) 存完后kill app, 然后重启app, 在我的MainActivity中取值,这时有值。 再kill app 重启app,然后没有值。

后来我这样存,

 val time: Long = System.currentTimeMillis()
val sp = context.getSharedPreferences("fpp",Context.MODE_PRIVATE)
sp.edit().putLong(Keys.UpdateTime,time).apply()

这样取 val sp = context.getSharedPreferences("fpp", Context.MODE_PRIVATE) val lastTime= sp.getLong(Keys.UpdateTime,-1) 就没有问题了, 不知道怎么回事?

morefreeliang avatar Mar 11 '22 09:03 morefreeliang