gpt4 book ai didi

Android onSaveInstanceState 包

转载 作者:行者123 更新时间:2023-11-29 00:12:04 26 4
gpt4 key购买 nike

当 android 由于系统限制而杀死您的进程时,它使您能够通过将数据存储在一个包中来跨进程持久保存数据。如果您的进程被终止,这个包保存在哪里?它存在于哪个进程中?它住在内存中的什么地方?它存在于内核内存中吗?

最佳答案

内核内存是一个 protected 内存空间,其中仅驻留内核代码等关键代码。这是为了防止来自用户的数据和内核的数据的干扰,以及其他性能和设计原因。内核内存将在重启后保留。

Bundle 中保存的数据在 onSaveInstanceState() 方法中传递 - 在用户离开 Activity 之前,而不是在 Activity 被销毁之前。这可能意味着内存没有像存储卡那样写入静态内存区域。 Bundle 确实会以更动态的方式持久化。

虽然这个问题还没有直接回答,但看起来这是 RAM 上的内存。当您查看 Android 设备的性能时,具有更多 RAM 的最新设备似乎能够更长时间地保留应用程序

来自 http://developer.android.com/training/basics/activity-lifecycle/recreating.html 的官方文档,据了解,这段内存是安卓自己追踪的。

By default, the system uses the Bundle instance state to save information about each View object in your activity layout (such as the text value entered into an EditText object). So, if your activity instance is destroyed and recreated, the state of the layout is restored to its previous state with no code required by you. However, your activity might have more state information that you'd like to restore, such as member variables that track the user's progress in the activity.

To save additional data about the activity state, you must override the onSaveInstanceState() callback method. The system calls this method when the user is leaving your activity and passes it the Bundle object that will be saved in the event that your activity is destroyed unexpectedly. If the system must recreate the activity instance later, it passes the same Bundle object to both the onRestoreInstanceState() and onCreate() methods.

另请记住,当设备关闭时,此 Bundle 会被销毁。 Android 可能为此专门设计了一个内存区域,但无论哪种方式,它都位于 RAM 中的某个位置。

关于Android onSaveInstanceState 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29550915/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com