当前位置:网站首页>Kotlin compose state recovery remembersaveable and remember
Kotlin compose state recovery remembersaveable and remember
2022-06-26 06:39:00 【Ango cannot move】
rememberSaveable Data status can be saved . Let the data remain unchanged when the screen is rotated
First realize Parcelable Interface
Kotlin Fast implementation Parcelable Interface _ Ango Mobile Blog -CSDN Blog
Code
package com.anguomob.jecpack.activity.compose.parcelable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme.colors
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.anguomob.jecpack.bean.City
@Composable
fun CityScreen() {
val (city, setCity) = rememberSaveable {
mutableStateOf(City(" Beijing 1", " China 1"))
}
Row(modifier = Modifier.padding(10.dp), verticalAlignment = Alignment.CenterVertically) {
TextButton(onClick = {
setCity(City(" Beijing ", " China "))
}, colors = ButtonDefaults.buttonColors()) {
Text(text = " Click Modify ")
}
Text(text = "${city.name} ${city.country}")
}
}First, modify the data
Then rotate the screen
You will find that the data has not changed

If used
remember{}
Click modify data Then rotate the screen
The data will become the value before modification ,.
边栏推荐
- Web components series (10) -- realize the basic layout of mycard
- Differences, advantages and disadvantages between synchronous communication and asynchronous communication
- 成水最多的容器
- How can an enterprise successfully complete cloud migration?
- zip(*arg)的用法
- [digital signal processing] basic sequence (basic sequence lists | unit pulse sequence | unit pulse function | discrete unit pulse function | difference between unit pulse function and discrete unit p
- MySQL 索引底层原理
- Go language learning notes 1.2- variables
- How to make the main thread wait for the sub thread to execute before executing
- Understanding of nil in go language
猜你喜欢
Everything is a vector. The service practice of iqiyi online vector recall project

Marketing skills: compared with the advantages of the product, it is more effective to show the use effect to customers
The sysdig 2022 cloud native security and usage report found that more than 75% of the running containers have serious vulnerabilities

EFK昇級到ClickHouse的日志存儲實戰

Jasminum plug-in of Zotero document management tool
Customer Stories | Netease spring breeze: the "spring breeze" of the fun industry, reaching out to all areas through in-depth interaction

DS18B20详解

Transformer中的Self-Attention以及Multi-Head Self-Attention(MSA)

Pagoda server setup and database remote connection

DPDK——TCP/UDP协议栈服务端实现(二)
随机推荐
typescript的class结合接口(interface)的简单使用
Decision tree learning notes
寶塔服務器搭建及數據庫遠程連接
Ppt template crawler case
Understanding of nil in go language
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
[golang] time related
Efk upgrade to Clickhouse log storage practice
How to select and build a real-time data warehouse scheme
我在腾讯做测试的这几年...
Gof23 - builder mode
How to set MySQL triggers is a simple tutorial for novices
Format one insert per line using mysqldump- Using mysqldump to format one insert per line?
Marketing skills: compared with the advantages of the product, it is more effective to show the use effect to customers
Gof23 - prototype mode
3.pyinstaller模块介绍
稀疏数组sparsearray
Alarm operation and Maintenance Center | build an efficient and accurate alarm collaborative processing system
3.pyinstaller module introduction
Go学习笔记1.3-变量的数据类型篇