当前位置:网站首页>Understand the basic concept of datastore in Android kotlin and why SharedPreferences should be stopped in Android
Understand the basic concept of datastore in Android kotlin and why SharedPreferences should be stopped in Android
2022-07-05 22:06:00 【Knowledge fatness】
stay Android Store a small amount of data in , Such as telephone number 、 Name or person, etc .Android Used by developers SharedPreferencesAPI. But for security and asynchronous transactions , Google suggests using DataStore .
SharedPreferences
these SharedPreferencesAPIdata For reading and writing stored in Android Based on XML Key value pairs in the file of .SharedPreferences Allow application developers to store small amounts of data , Such as String、Int、Long、Double etc. , Used for configuration 、 Settings, etc . You can still go through Place complex custom class objects ,Serializable But this is not usually recommended .
In order to use it , First you need to get an instance ,SharedPreferences Then you can use get*() The method in the following example reads data .
val preferences = this.getSharedPreferences("SOME_NAME", Context.MODE_PRIVATE)
// Reading the values from Preferences
val myStr = preferences.getString("myStrKey", "DEFAULT_STR")
val myLong = preferences.getLong("myLongKey", 0)
val myInt = preferences.getInt("myIntKey", 1)
val myDouble = preferences.getDouble("myDoubleKey", 0.0)
Or you can visit SharedPreferences.Editor Objects and calls put*() Method to write a value , Finally, you can commitorapply() Method to save these changes .
边栏推荐
- EL与JSTL注意事项汇总
- 从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
- 华为快游戏调用登录接口失败,返回错误码 -1
- Leetcode simple question: check whether each row and column contain all integers
- 每日刷题记录 (十四)
- Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
- 大约SQL现场“这包括”与“包括在”字符串的写法
- 如何组织一场实战攻防演练
- Meituan dynamic thread pool practice ideas, open source
- Oracle views the data size of a table
猜你喜欢

元宇宙中的三大“派系”

Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer

EBS Oracle 11g cloning steps (single node)

Business learning of mall commodity module

Leetcode simple question: find the nearest point with the same X or Y coordinate

装饰器学习01

Two stage locking protocol for concurrency control

Interview questions for famous enterprises: Coins represent a given value

U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程

Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
随机推荐
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
Text组件新增内容通过tag_config设置前景色、背景色
Interview questions for famous enterprises: Coins represent a given value
Codeforces 12D ball tree array simulation 3 sorting elements
Storage optimization of performance tuning methodology
How to develop and introduce applet plug-ins
Common interview questions of JVM manufacturers
Official clarification statement of Jihu company
A trip to Suzhou during the Dragon Boat Festival holiday
Image editor for their AutoLayout environment
Meituan dynamic thread pool practice ideas, open source
Oracle triggers
poj 3237 Tree(樹鏈拆分)
Overview of concurrency control
Dbeaver executes multiple insert into error processing at the same time
Analyse des risques liés aux liaisons de microservices
MySQL服务莫名宕机的解决方案
Poj3414广泛搜索
Web3为互联网带来了哪些改变?
Implementation technology of recovery