Application.onLowMemory() 未调用
我创建了自己的应用程序类。
我尝试调试它,代码在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为有任何保证会调用此方法。
来自文档:
由于未定义调用它的点,因此它可以选择从不调用它。
一般来说,Android 可以随时杀死您的应用程序,只要它在后台即可。您应该只依赖生命周期中的方法(例如 onPause、onStop、onDestroy),这些方法明确声明保证调用它们以执行任何必要的清理。
I don't think that there are any guarantees that this method will ever be called.
From the docs:
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.