当前位置:网站首页>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 .
边栏推荐
- 如何開發引入小程序插件
- poj 3237 Tree(树链拆分)
- Implementation technology of recovery
- Experienced inductance manufacturers tell you what makes the inductance noisy. Inductance noise is a common inductance fault. If the used inductance makes noise, you don't have to worry. You just need
- Web3为互联网带来了哪些改变?
- EL与JSTL注意事项汇总
- How to use tensorflow2 for cat and dog classification and recognition
- Leetcode simple question: check whether each row and column contain all integers
- 【愚公系列】2022年7月 Go教学课程 004-Go代码注释
- Oracle triggers
猜你喜欢

Overview of database recovery

Oracle checkpoint queue - Analysis of the principle of instance crash recovery

A trip to Suzhou during the Dragon Boat Festival holiday

Storage optimization of performance tuning methodology

Alternating merging strings of leetcode simple questions

Oracle advanced query

MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server

K210 learning notes (IV) k210 runs multiple models at the same time

Interview questions for famous enterprises: Coins represent a given value

Serializability of concurrent scheduling
随机推荐
Codeforces 12D ball tree array simulation 3 sorting elements
Index optimization of performance tuning methodology
多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
A long's perception
Overview of database recovery
A trip to Suzhou during the Dragon Boat Festival holiday
The simple problem of leetcode is to split a string into several groups of length K
华为快游戏调用登录接口失败,返回错误码 -1
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
Create a virtual machine on VMware (system not installed)
等到产业互联网时代真正发展成熟,我们将会看待一系列的新产业巨头的出现
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
MySQL actual combat 45 lecture learning (I)
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
Interprocess communication in the "Chris Richardson microservice series" microservice architecture
如何開發引入小程序插件
Cross end solutions to improve development efficiency
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
大约SQL现场“这包括”与“包括在”字符串的写法
Learning of mall permission module