Application.onLowMemory() not invloked

被刻印的时光 ゝ 提交于 2019-12-30 07:54:10

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5329745/application-onlowmemory-not-invloked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!