gpt4 book ai didi

android - 故意让系统关闭并重新启动应用程序

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

我一直看到我的应用程序返回错误,它在系统停止后强制关闭,用户稍后将其带回前台。

我对导致此问题的原因有所了解,但我希望能够在尝试修复之前重现此错误。

有谁知道让 android 系统表现得像它需要我的应用程序正在使用的内存并关闭它以便我可以轻松且持续地重现此错误的方法?

最佳答案

使用 Dev Tools app在您的模拟器上,您可以让操作系统在应用程序停止后立即销毁它。

来自文档:

立即销毁 Activity

Tells the system to destroy an activity as soon as it is stopped (as if Android had to reclaim memory). This is very useful fortesting the onSaveInstanceState(Bundle) / onCreate(android.os.Bundle)code path, which would otherwise be difficult to force. Choosing thisoption will probably reveal a number of problems in your applicationdue to not saving state. For more information about saving anactivity's state, see the Activities document.

进入 Dev Tools 应用程序后,您可以在 Development Settings 下找到它。因此,在运行您的应用程序时,您可以切换到另一个应用程序(例如单击模拟器的硬件电话按钮),然后返回您的应用程序以测试销毁/创建过程。

关于android - 故意让系统关闭并重新启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10192697/

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