Application.onLowMemory() 未调用

发布于 2024-10-24 04:17:28 字数 271 浏览 0 评论 0原文

我创建了自己的应用程序类。

我尝试调试它,代码在 Application.onCreate() 处停止,但不会在 onLowMemory 处停止。

为了测试该场景,我打开了许多其他高内存应用程序。

我看到的是调试会话终止(在 Eclipse 中)并且我的一些静态变量变成了 null - 表明进程已经结束。

调试不仅没有在方法的断点处停止,我还放置了 Log.e(...) 行,但也没有看到它。

知道为什么没有调用该方法吗?

谢谢。

I've create an Application class of my own.

I try to debug it and the code stops at Application.onCreate() but does not stop at onLowMemory.

To test the scenario I open a lot of other high memory applications.

What I see is that the debug session terminated (in eclipse) and some of my static variables turned to null - indicates the the process has ended.

Not only did the debug NOT stop @ the breakpoint of the method, I've put a Log.e(...) line and don't see it as well.

Any idea of why the method was not invoked?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉梦枕江山 2024-10-31 04:17:29

我不认为有任何保证会调用此方法。

来自文档

虽然这的确切点
将被调用未定义,
一般会发生在
所有后台进程都已完成的时间
被杀,即在到达之前
杀死托管进程的点
我们的服务和前台 UI
想要避免杀戮。

由于未定义调用它的点,因此它可以选择从不调用它。

一般来说,Android 可以随时杀死您的应用程序,只要它在后台即可。您应该只依赖生命周期中的方法(例如 onPause、onStop、onDestroy),这些方法明确声明保证调用它们以执行任何必要的清理。

I don't think that there are any guarantees that this method will ever be called.

From the docs:

While the exact point at which this
will be called is not defined,
generally it will happen around the
time all background process have been
killed, that is before reaching the
point of killing processes hosting
service and foreground UI that we
would like to avoid killing.

Since the point at which it is called is not defined, it could choose to never call it.

In general, Android is free to kill your Application whenever it wants, as long as it is in the background. You should only rely on methods in the lifecycle (like onPause, onStop, onDestroy) that specifically state that they are guaranteed to be called in order to do any necessary cleanup.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文