回调的Andr​​oid活动的部队关闭前? [英] Callback before Force Close of Android Activity?

查看:115
本文介绍了回调的Andr​​oid活动的部队关闭前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一些紧急清理code只是我的应用程序崩溃之前执行。我尝试使用的onDestroy(),, onFinal()并完成()无济于事。在Android活动是这可能吗?

I'd like to have some emergency cleanup code execute just before my app crashes. I tried using onDestroy(),, onFinal() and finalize() to no avail. Is this possible in an Android Activity?

推荐答案

嗯,我会建议没有在第一时间你的应用程序崩溃。如果有一些可能会崩溃,只是把一个try / catch周围并妥善处理。

Well, I would recommend not having your app crash in the first place. If there's something that COULD crash, just put a try/catch around it and handle it properly.

或者,某种全球性的try / catch,你可以使用 Thread.setUncaughtExceptionHandler()。最后,你甚至可以考虑 Runtime.addShutdownHook ,但是这是最有可能是一个坏主意。

Or, as some sort of global try/catch, you can use Thread.setUncaughtExceptionHandler(). Finally, you could even consider Runtime.addShutdownHook, but that's most likely a bad idea.

这篇关于回调的Andr​​oid活动的部队关闭前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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