"Android"--use Uncaughtexceptionhandler to catch global exceptions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.