回调的Andr​​oid活动的部队关闭前?回调、部队、Andr、oid

由网友(终归单人心。)分享简介:我想有一些紧急清理code只是我的应用程序崩溃之前执行。我尝试使用的onDestroy(),, onFinal()并完成()无济于事。在Android活动是这可能吗?I'd like to have some emergency cleanup code execute just before my app cras...

我想有一些紧急清理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.

阅读全文

相关推荐

最新文章