简体   繁体   English

在android中检测应用程序崩溃

[英]Detect app crash in android

I'm building an app that sometimes crashes, I want to know that it crashed in the next time I opened it so I can suggest to the user some post-crash options. 我正在构建一个有时会崩溃的应用程序,我想知道它在下次打开它时崩溃了所以我可以向用户建议一些崩溃后的选项。 How can I detect the crash? 我怎样才能发现崩溃? Also I want to be able to save the user's work before it crashes, I means real time detection of crash, can I do it without knowing where it crashed? 此外,我希望能够在崩溃之前保存用户的工作,我的意思是实时检测崩溃,我可以在不知道崩溃的地方进行吗?

You will need to know where it crashed in order to set the try / catch blocks in the right place to, er, catch the crash and save the data or whatever you have in mind. 您需要知道崩溃的位置,以便在正确的位置设置try / catch块,然后catch崩溃并保存数据或您想到的任何内容。

This is known as "graceful" termination if you want to consider it in more detail. 如果您想更详细地考虑它,这被称为“优雅”终止。

Unfortunately neither Java destructor/finalize methods nor lifecycle methods such as onDestroy are anywhere near as robust as try / catch blocks so I'm afraid that is your only option, and how many of us deal with exception prevention. 不幸的是,Java析构函数/最终化方法和生命周期方法(如onDestroy都不像try / catch块那样强大,所以我担心这是你唯一的选择,我们中有多少人处理异常预防。 No-one would wittingly provide a user experience that crashes, much less with loss of their data. 没有人能够提供崩溃的用户体验,更不用说丢失数据了。

Take a took at the ACRA library . 参观ACRA图书馆 You can configure it so whenever a crash happens you can control it and even send the crash log by email 您可以对其进行配置,以便每当发生崩溃时您都可以控制它,甚至可以通过电子邮件发送崩溃日志

您可以使用try/catch ,然后在catch发送Exception详细信息。

这些答案中提到了 UncaughtExceptionHandler 并在某些文件中写入崩溃报告或以其他方式使用它。

ACRA is already mentioned. 已经提到过ACRA

However for paid version, I found BugSnag is very good at this. 但是对于付费版本,我发现BugSnag非常擅长这个。 Or if you want to take the extra mile, try AppSee . 或者,如果您想加倍努力,请尝试AppSee

AppSee even has video recording session of how the crash happens. AppSee甚至还有关于崩溃如何发生的视频录制会话。 It is from tapping that button on the second list, the menu button or even when the user slides left in your viewpager. 它来自点击第二个列表上的该按钮,菜单按钮,甚至当用户在您的viewpager中向左滑动时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM