After integrating the Statistics SDK (Friend League statistics, Baidu statistics, etc.), there is a very useful test function: Error analysis! This feature is able to feed back crashes (runtimeexception) problems encountered in the running of the program to the server, helping developers to improve their products and adapt their machines.
However, if the SDK is not integrated in the company's Android development, how should this function be implemented? Let's take a look at how to use Uncaughtexceptionhandler to catch exceptions.
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 place to process the code and then you need to trigger it:
Add in the OnCreate of the program's entry activity:
Thread.setdefaultuncaughtexceptionhandler (New Crashhandler ());
is not very easy ah!