gpt4 book ai didi

Android bundle = .NET session []?

转载 作者:行者123 更新时间:2023-11-29 22:29:21 25 4
gpt4 key购买 nike

Android Bundle 的描述说:

Bundles are Android's way of maintaining and passing program state. The system is constructed around the assumption that any program (characterized by a collection of activities) may be preempted at any time, and if the system resources are low, may be subsequently killed. To handle this difficulty, a Bundle called an icicle is saved whenever the activity is preempted.

Like with a hash table or dictionary, items added to the Bundle are given a key which is later used to retrieve the data (using data-type specific methods like getCharacter(String key) and getParcelable(String key)). When you are creating activities, be sure to save any important state information into the icicle given to onFreeze so that you can restore your program in onCreate if it is killed while suspended.

Bundle 和 .NET 中的 Session[] 一样吗?

最佳答案

不完全是,不。

在 .NET 中,您可以随时随地访问 State 对象,并且您可以非常确定放置在其中的对象在您调用它时仍然存在。但是 session 会过期,除非您在 View 状态中保存了任何内容,否则该数据将丢失。

Android 由于操作系统的性质而使用 Bundle,它会让您的应用程序在保留状态的后台“活着”,但如果它认为您的应用程序处于空闲状态并且可以被杀死,它会杀死您的应用程序应用程序释放资源。在您的应用程序进程被终止之前,它将调用 onFreeze()(现在重命名为 onSaveInstanceState()),这将使您有机会将数据保存到将要传递的 Bundle下次你的应用程序启动时 onCreate (这样你就可以再次初始化你的屏幕)。

关于Android bundle = .NET session []?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4785524/

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