How do I obtain crash-data from my Android application?

前端 未结 30 3204
庸人自扰
庸人自扰 2020-11-22 01:10

How can I get crash data (stack traces at least) from my Android application? At least when working on my own device being retrieved by cable, but ideally from any instance

30条回答
  •  佛祖请我去吃肉
    2020-11-22 01:31

    Ok, well I looked at the provided samples from rrainn and Soonil, and I found a solution that does not mess up error handling.

    I modified the CustomExceptionHandler so it stores the original UncaughtExceptionHandler from the Thread we associate the new one. At the end of the new "uncaughtException"- Method I just call the old function using the stored UncaughtExceptionHandler.

    In the DefaultExceptionHandler class you need sth. like this:

    public class DefaultExceptionHandler implements UncaughtExceptionHandler{
      private UncaughtExceptionHandler mDefaultExceptionHandler;
    
      //constructor
      public DefaultExceptionHandler(UncaughtExceptionHandler pDefaultExceptionHandler)
      {
           mDefaultExceptionHandler= pDefaultExceptionHandler;
      }
      public void uncaughtException(Thread t, Throwable e) {       
            //do some action like writing to file or upload somewhere         
    
            //call original handler  
            mStandardEH.uncaughtException(t, e);        
    
            // cleanup, don't know if really required
            t.getThreadGroup().destroy();
      }
    }
    

    With that modification on the code at http://code.google.com/p/android-remote-stacktrace you have a good working base for logging in the field to your webserver or to sd-card.

提交回复
热议问题