当前位置:网站首页>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 ,.
边栏推荐
- GoF23—抽象工厂模式
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
- Typescript type
- Go学习笔记1.3-变量的数据类型篇
- DPDK——TCP/UDP协议栈服务端实现(二)
- Alarm operation and Maintenance Center | build an efficient and accurate alarm collaborative processing system
- Past events of Xinhua III
- Get the first and last days of the current month, and the first and last days of the previous month
- Go language learning notes 1.1
- Unsatisfied dependency expressed through field ‘baseMapper‘; nested exceptio
猜你喜欢
![[spark] how to implement spark SQL field blood relationship](/img/8e/96f83844b480916b2662b0cf1fdf65.jpg)
[spark] how to implement spark SQL field blood relationship

DS18B20 details

Decision tree learning notes

Library management system

LabVIEW arduino TCP / IP Remote Intelligent Home System (Project section - 5)

Gof23 - prototype mode

连接数服务器数据库报:错误号码2003Can‘t connect to MySQL server on ‘服务器地址‘(10061)
A new paradigm for large model application: unified feature representation optimization (UFO)

Load balancer does not have available server for client: userservice problem solving

Pagoda server setup and database remote connection
随机推荐
zip(*arg)的用法
营销技巧:相比较讲产品的优点,更有效的是要向客户展示使用效果
vs code 使用 prettier 格式化 js 的时候, 函数定义的名称和括号之间有一个空格, 而 eslit 又不允许这个空格.
Unsatisfied dependency expressed through field ‘baseMapper‘; nested exceptio
Typescript type
~94 zoom
浏览器的四大内核:Trident,Gecko,Webkit,Blink
Load balancer does not have available server for client: userservice problem solving
How to select and build a real-time data warehouse scheme
Load balancer does not have available server for client: userService问题解决
Pagoda server setup and database remote connection
Distribution operation of D
面试官:测试计划和测试方案有什么区别?
DPDK——TCP/UDP协议栈服务端实现(一)
Temperature alarm
3.pyinstaller module introduction
STM 32 uses cube to generate Tim to trigger ADC and transmit through DMA
Pychart cannot run designer Exe (this application failed to start because no Qt platform plugin could be I appears)
Research Report on market supply and demand and strategy of natural organic beauty industry in China
Research Report on market supply and demand and strategy of China's microneedle device industry