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

前端 未结 30 2554
庸人自扰
庸人自扰 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:41

    It is possible to handle these exceptions with Thread.setDefaultUncaughtExceptionHandler(), however this appears to mess with Android's method of handling exceptions. I attempted to use a handler of this nature:

    private class ExceptionHandler implements Thread.UncaughtExceptionHandler {
        @Override
        public void uncaughtException(Thread thread, Throwable ex){
            Log.e(Constants.TAG, "uncaught_exception_handler: uncaught exception in thread " + thread.getName(), ex);
    
            //hack to rethrow unchecked exceptions
            if(ex instanceof RuntimeException)
                throw (RuntimeException)ex;
            if(ex instanceof Error)
                throw (Error)ex;
    
            //this should really never happen
            Log.e(Constants.TAG, "uncaught_exception handler: unable to rethrow checked exception");
        }
    }
    

    However, even with rethrowing the exceptions, I was unable to get the desired behavior, ie logging the exception while still allowing Android to shutdown the component it had happened it, so I gave up on it after a while.

提交回复
热议问题