Recovery捕获应用崩溃框架,并能恢复崩溃页面。
1.安装教程
在项目根目录下的build.gradle文件中添加。
- allprojects {
- repositories {
- maven {
- url'https://s01.oss.sonatype.org/content/repositories/releases/'
- }
- }}
复制代码
在entry模块下的build.gradle文件中添加依赖。
- dependencies { implementation('com.gitee.chinasoft_ohos:Recovery:1.0.1')}
复制代码在sdk6,DevEco Studio2.2 beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
使用说明
在entry下的MyApplication中调用
- public class MyApplication extends AbilityPackage {
- @Override
- public void onInitialize() {
- super.onInitialize();
- Recovery.getInstance()
- .debug(true)
- .recoverInBackground(false)
- .recoverStack(true)
- .mainPage(MainAbility.class)
- .recoverEnabled(true)
- .callback(new MyCrashCallback())
- .silent(false, Recovery.SilentMode.RECOVER_ACTIVITY_STACK)
- .skip(TestAbility.class)
- .init(this);
- }
- static final class MyCrashCallback implements RecoveryCallback {
- @Override
- public void stackTrace(String exceptionMessage) {
- RecoveryLog.e("exceptionMessage:" + exceptionMessage);
- }
- @Override
- public void cause(String cause) {
- RecoveryLog.e("cause:" + cause);
- }
- @Override
- public void exception(String exceptionType, String throwClassName, String throwMethodName, int throwLineNumber) {
- RecoveryLog.e("exceptionType:" + exceptionType);
- RecoveryLog.e("throwClassName:" + throwClassName);
- RecoveryLog.e("throwMethodName:" + throwMethodName);
- RecoveryLog.e("throwLineNumber:" + throwLineNumber);
- }
- @Override
- public void throwable(Throwable throwable) {
- }
- }
- }
复制代码
2.重启功能需要在entry模块的config.json中 module 加入属性mainAbility
- "module": { "mainAbility" : "启动页的路径", .....}
复制代码
3. 组件完整代码地址