关于Android的Application的onTerminage接口

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/linxinfa/article/details/89605731

在App运行过程中有且仅有一个Application对象贯穿整个生命周期。
自己重写Application的时候,可以重写以下几个接口
onCreate: 在App启动时调用
onTerminate: 在App退出时调用
onLowMemory: 在低内存时调用
onConfigurationChanged: 在配置改变时调用,例如从竖屏变为横屏

这个onTerminate从字面看时在App退出时调用,但是实际上,无论是自行退出还是强行杀死App的进程,都不会被调用,Android明明提供了这个函数,同时提供了关于函数的解释:
This method is foe use in emulated process environments.
It will nerver be called on a production Android device, where process are removed by simply killing them; no user code (including this callback) is executed when doing so.

意思就是,onTerminate时提供模拟环境用的,在真机上永远不会被调用,无论是直接杀死进程还是代码退出。
如果想在App退出之前做一些操作,千万不要放在onTerminate方法中

猜你喜欢

转载自blog.csdn.net/linxinfa/article/details/89605731