Skip to content

Commit 6647210

Browse files
committed
Support commit function for EasySharedPreferences
1 parent 12a8dc2 commit 6647210

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

utils/src/main/java/com/haoge/easyandroid/easy/EasySharedPreferences.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ class EasySharedPreferences(clazz: Class<*>):SharedPreferences.OnSharedPreferenc
190190
handler.apply { }
191191
}
192192

193+
/**
194+
* 将类中的数据同步到SP容器中去。(同步执行)
195+
*/
196+
fun commit() {
197+
write()
198+
}
199+
193200
private fun getValid(value:String?, default:String):String =
194201
if (value.isNullOrEmpty()) default else value as String
195202

@@ -239,6 +246,10 @@ abstract class PreferenceSupport {
239246
// 将当前类中的修改。同步到sp中去(任务运行于子线程)
240247
EasySharedPreferences.find(javaClass).apply()
241248
}
249+
250+
fun commit() {
251+
EasySharedPreferences.find(javaClass).commit()
252+
}
242253
}
243254

244255
@Retention(AnnotationRetention.RUNTIME)

0 commit comments

Comments
 (0)