Detailed explanation of Android global exception capture instance

Android global exception capture

Today, let's talk about bugs that we, as program apes, encounter every day. Bugs are not terrible. What's terrible is the stack information when there is no bug, so it's particularly important to collect bug information. Generally, it can be easily collected by using a third party bugly or a friend alliance, but because the company does not allow the use of a third party, Android happens to have a native exception collection class uncaughtexceptionhandler, so today's blog starts with this class

The uncaughtexceptionhandler is known by its name, that is, it is used to handle exceptions that we have not caught. The specific use is divided into two steps

1. Implement our own exception handling class

We need to implement the thread.uncaughtexceptionhandler interface. When there are uncaught exceptions, we will call back the uncaughtexception (thread, throwable Ex) method

2. Set the crashhandler as the system default

The above is only an introduction to the use steps. I will directly post the code for the use in specific projects

Initialize in application

The crashhandler implementation class is as follows

Activity management class

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>