当前位置:网站首页>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 .
边栏推荐
- Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
- Business learning of mall commodity module
- [Yugong series] go teaching course 003-ide installation and basic use in July 2022
- AD637 usage notes
- Poj 3237 Tree (Tree Chain Split)
- Common interview questions of redis factory
- 阿龙的感悟
- poj 3237 Tree(树链拆分)
- Deeply convinced plan X - network protocol basic DNS
- Oracle views the data size of a table
猜你喜欢
How to view Apache log4j 2 remote code execution vulnerability?
A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
Huawei cloud modelarts text classification - takeout comments
Granularity of blocking of concurrency control
Stored procedures and stored functions
Web3为互联网带来了哪些改变?
Meituan dynamic thread pool practice ideas, open source
The statistics of leetcode simple question is the public string that has appeared once
Pl/sql basic case
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
随机推荐
Database recovery strategy
Cross end solutions to improve development efficiency
Livelocks and deadlocks of concurrency control
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
Oracle hint understanding
Ad637 notes d'utilisation
Overview of database recovery
AD637使用笔记
Interview questions for famous enterprises: Coins represent a given value
EBS Oracle 11g cloning steps (single node)
如何向mongoDB中添加新的字段附代码(全)
Search: Future Vision (moving sword)
HDU 4391 paint the wall segment tree (water
Oracle triggers
Business learning of mall commodity module
Business learning of mall order module
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
元宇宙中的三大“派系”
Pl/sql basic case
How can Huawei online match improve the success rate of player matching