当前位置:网站首页>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 .
边栏推荐
- DataGrid directly edits and saves "design defects"
- Concurrency control of performance tuning methodology
- U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
- How to view Apache log4j 2 remote code execution vulnerability?
- 华为快游戏调用登录接口失败,返回错误码 -1
- Alternating merging strings of leetcode simple questions
- Granularity of blocking of concurrency control
- EBS Oracle 11g cloning steps (single node)
- boundary IoU 的计算方式
- Database tuning solution
猜你喜欢
Oracle advanced query
Deeply convinced plan X - network protocol basic DNS
Shell script, awk condition judgment and logic comparison &||
Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
Cobaltstrike builds an intranet tunnel
Stored procedures and stored functions
华为快游戏调用登录接口失败,返回错误码 -1
Leetcode simple question check whether all characters appear the same number of times
2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*
Leetcode simple question: find the nearest point with the same X or Y coordinate
随机推荐
HDU 4391 Paint The Wall 段树(水
A substring with a length of three and different characters in the leetcode simple question
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
Codeforces 12D ball tree array simulation 3 sorting elements
Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned
NET中小型企业项目开发框架系列(一个)
等到产业互联网时代真正发展成熟,我们将会看待一系列的新产业巨头的出现
Livelocks and deadlocks of concurrency control
华为快游戏调用登录接口失败,返回错误码 -1
Analyse des risques liés aux liaisons de microservices
他们主动布局(autolayout)环境的图像编辑器
Common interview questions of redis factory
POJ 3237 tree (tree chain splitting)
Ad637 notes d'utilisation
An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
Stored procedures and stored functions
Oracle views the data size of a table
Learning of mall permission module
MySQL actual combat 45 lecture learning (I)
如何开发引入小程序插件