After the comprehensive Statistics SDK (Eurostat friends, Baidu Statistics). There is a very advantageous functional test: Error analysis. This feature can help developers improve their products by encountering crash (runtimeexception) feedback to the server during program execution. Multifunction adapter Machine.
However, in the company's Android development does not integrate these SDKs, that should be how to implement this function? Let's take a look at how to use Uncaughtexceptionhandler to catch the exception.
The first implementation creates a class that implements the Uncaughtexceptionhandler interface. The code is as follows:
public class Crashhandler implements Uncaughtexceptionhandler {@Overridepublic void uncaughtexception (thread thread, Throwable ex) {//Handle exception LOG.E ("Crash", Thread.getname () +ex.tostring ());//Send To Server//dialog reminder}}
There is a processing code. And then you need to trigger it somewhere:
Add in the OnCreate of the program's entry activity:
Thread.setdefaultuncaughtexceptionhandler (New Crashhandler ());
is not very easy ah!
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
"Android"--use Uncaughtexceptionhandler to catch global exceptions