Recreating an Activity

本文介绍了如何在Android应用中保存和恢复Activity的状态信息。通过实现onSaveInstanceState()方法,开发者可以将关键的数据存储到Bundle对象中,从而确保在设备配置改变(如屏幕旋转)时,应用能够正确地恢复到之前的状态。文章还提到了在onCreate()方法中检查Bundle是否为空的重要性,并解释了onRestoreInstanceState()方法的调用时机。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.

Save Your Activity State

1.1

To save additional state information for your activity, you must implement onSaveInstanceState() and add key-value pairs to the Bundle object.


2.

Restore Your Activity State 

2.1

onCreate()you must check whether the state Bundle is null before you attempt to read it. 

2.2

The system calls onRestoreInstanceState() only if there is a saved state to restore, so you do not need to check whether the Bundle is null



Handling Runtime Changes

To learn more about recreating your activity due to a restart event at runtime (such as when the screen rotates), read Handling Runtime Changes.







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值