当前位置:网站首页>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 .
边栏推荐
- boundary IoU 的计算方式
- Codeforces 12D ball tree array simulation 3 sorting elements
- Talking about MySQL index
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- How to develop and introduce applet plug-ins
- 【愚公系列】2022年7月 Go教学课程 004-Go代码注释
- Evolution of large website architecture and knowledge system
- The real situation of programmers
- Index optimization of performance tuning methodology
- Microservice link risk analysis
猜你喜欢
Learning of mall permission module
Performance monitoring of database tuning solutions
Recovery technology with checkpoints
MySQL服务莫名宕机的解决方案
元宇宙中的三大“派系”
Matlab draws a cute fat doll
Huawei cloud modelarts text classification - takeout comments
数据泄露怎么办?'华生·K'7招消灭安全威胁
Leetcode simple question check whether all characters appear the same number of times
Livelocks and deadlocks of concurrency control
随机推荐
Evolution of large website architecture and knowledge system
华为联机对战如何提升玩家匹配成功几率
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
poj 3237 Tree(樹鏈拆分)
Multiplexing of Oracle control files
About the writing method of SQL field "this includes" and "included in" strings
Matlab | app designer · I used Matlab to make a real-time editor of latex formula
Implementation technology of recovery
Bitbucket installation configuration
Interview questions for famous enterprises: Coins represent a given value
Leetcode simple question ring and rod
Decorator learning 01
Shell script, awk uses if, for process control
Leetcode simple question: the minimum cost of buying candy at a discount
Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
Oracle triggers
华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010
Web3为互联网带来了哪些改变?
boundary IoU 的计算方式