Why do we need feedback on the crash report?
Android applicationsProgramTo avoid crash. Although zero-crash is the ultimate goal pursued by programmers, the reality is that programmers can only minimize the occurrence of crash, and it is almost impossible to completely eliminate it. Maybe you think that your application is almost perfect and can easily withstand the devil's test in the testing department. But when your application is released to the market, it may not be so lucky to face millions or even tens of millions of users.
For the above reasons, a crash feedback mechanism is required for general applications. Based on the feedback, the programmer canCodeTo make the next version more stable.
How to provide feedback?
First, let's take a look at how to capture the occurrence of crash.
There is an interface in Java, uncaughtexceptionhandler. first look at the description.
Static Interface
|
Thread. uncaughtexceptionhandler WhenThreadWhen an uncaptured exception is suddenly terminated, the handler interface is called. |
Let's take a look at a method in the Thread class.
Static void
|
Setdefaultuncaughtexceptionhandler( Thread. uncaughtexceptionhandlerEh) Sets the default handler that is called when the thread is suddenly terminated because no exception is caught and no other handler is defined for the thread. |
After reading these APIs, we can see that we need to implement such an interface and then set the handler in the main thread of the program.
Public ClassDefaultexceptionhandlerImplementsUncaughtexceptionhandler {// inherits from uncaughtexceptionhandler
Public VoidUncaughtexception (thread, throwable ex ){} // Handle exceptions that are not captured
}
1. send an email
2. Send to server
3. Wait...
In this way, we can handle the crashreport on the mobile phone to see what problems the user has encountered.