一个终端app运行于用户手中,可能由于不同操作场景产生产生崩溃等错误,一个良好的apk应该能够监听到普通用户操作时产生的错误。那么在android平台中如何监听到一个app运行时产生的错误,并将该错误报告到后台??
该需求在android源码中就可以找到答案。在android源码中
frameworks/base/tests/SmokeTest/tests/src/com/android/smoketest/
ProcessErrorsTest.java
这是一个smoke test的例子。顺便提一下smoke test:smoke test (冒烟测试)在测试中发现问题,找到了一个Bug,然后开发人员会来修复这个Bug。这时想知道这次修复是否真的解决了程序的Bug,或者是否会对其它模块造成影响,就需要针对此问题进行专门测试,这个过程就被称为Smoke Test。
【1】如何监听错误提报告,参考
ProcessErrorsTest.java如下片断:
// See if there are any errors. We wait until down here to give ANRs as much time as
// possible to occur.
final Collection<ProcessError> errProcs =
ProcessError.fromCollection(mActivityManager.getProcessesInErrorState());
// Distinguish the asynchronous crashes/ANRs from the synchronous ones by checking the
// crash package name against the package name for {@code app}
if (errProcs != null) {