Android:onDestroy() 或 Application 类中的类似方法 [英] Android: onDestroy() or similar method in Application class

查看:56
本文介绍了Android:onDestroy() 或 Application 类中的类似方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在扩展 Application 类来处理一些需要上下文的全局变量.我知道 Application 类中有 onCreate() 方法在活动中的任何其他 onCreate() 之前被调用,但是 我想知道 Application 类中是否有 onDestroy() 或类似的方法可以被覆盖 这样我就可以将变量存储在持久内存中,取消注册侦听器并将最后一条消息发送到应用程序进程被杀死之前的服务器?如果没有,有没有其他方法可以做到这一点?

I am extending Application class to work with some global variables that need context. I know there is onCreate() method in the Application class that gets called before any other onCreate() in activities, but I would like to know if there is onDestroy() or similar method in the Application class that could be overridden so that I would be able to store variables in persistent memory, unregister listener and send last message to server before app process gets killed? If not, is there any other way to do that?

推荐答案

Application 类的生产设备上没有此类回调.

There is no such call back on a production device for the Application class.

您想要做的事情通常应该在做出更改后立即完成,或者在相应应用组件的 onPause() 中完成.

The things you want to do should usually be done right after the changes are made, or in the onPause() of the respective app component.

这篇关于Android:onDestroy() 或 Application 类中的类似方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆