项目
在 GitHub 查看
Sunzxyong/Recovery
Sunzxyong/Recovery has 1,693 GitHub stars and 218 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-08 02:28 UTC. Last push 2019-02-17.
a crash recovery framework.(一个App异常恢复框架)
实测星标增长
- 24小时
- 0
- 7天
- 更新延迟
- 15天
- 更新延迟
- 1个月
- 更新延迟
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README-Chinese.md
原文Recovery
A crash recovery framework!
Introduce
“Recovery”帮助你自动处理程序在运行时的Crash,它含有以下几点功能
- 自动恢复Activity Stack和数据
- 支持只恢复栈顶Activity
- Crash信息的显示与保存
- 应用重启或者清空缓存
- 一分钟内两次恢复失败不再恢复而进行重启应用
Art

Usage
Reference
Gradle
implementation 'com.zxy.android:recovery:1.0.0'
或者
debugImplementation 'com.zxy.android:recovery:1.0.0'
releaseImplementation 'com.zxy.android:recovery-no-op:1.0.0'
Maven
<dependency>
<groupId>com.zxy.android</groupId>
<artifactId>recovery</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
Init
你可以使用类似如下初始化代码在你自定义的Application中进行初始化:
Recovery.getInstance()
.debug(true)
.recoverInBackground(false)
.recoverStack(true)
.mainPage(MainActivity.class)
.recoverEnabled(true)
.callback(new MyCrashCallback())
.silent(false, Recovery.SilentMode.RECOVER_ACTIVITY_STACK)
.skip(TestActivity.class)
.init(this);
如果你不想在应用发生Crash时显示RecoveryActivity,你可以使用静默恢复来进行无界面的恢复你的应用,那么请使用类似如下初始化代码在你自定义的Application中进行初始化:
Recovery.getInstance()
.debug(true)
.recoverInBackground(false)
.recoverStack(true)
.mainPage(MainActivity.class)
.recoverEnabled(true)
.callback(new MyCrashCallback())
.silent(false, Recovery.SilentMode.RECOVER_ACTIVITY_STACK)
.skip(TestActivity.class)
.init(this);
如果你仅仅需要在开发时显示RecoveryActivity界面来获取debug数据,而在线上版本不显示,那么可以设置recoverEnabled(false);
Arguments
| Argument | Type | Function |
|---|---|---|
| debug | boolean | 是否开启debug模式 |
| recoverInBackgroud | boolean | 当应用在后台时发生Crash,是否需要进行恢复 |
| recoverStack | boolean | 是否恢复整个Activity Stack,否则将恢复栈顶Activity |
| mainPage | Class<? extends Activity> | 回退的界面 |
| callback | RecoveryCallback | 发生Crash时的回调 |
| silent | boolean,SilentMode | 是否使用静默恢复,如果设置为true的情况下,那么在发生Crash时将不显示RecoveryActivity界面来进行恢复,而是自动的恢复Activity的堆栈和数据,也就是无界面恢复 |
SilentMode
- RESTART - 重启应用
- RECOVER_ACTIVITY_STACK - 恢复Activity堆栈
- RECOVER_TOP_ACTIVITY - 恢复栈顶Activity
- RESTART_AND_CLEAR - 重启应用并清空缓存数据
Callback
public interface RecoveryCallback {
void stackTrace(String stackTrace);
void cause(String cause);
void exception(String throwExceptionType, String throwClassName, String throwMethodName, int throwLineNumber);
void throwable(Throwable throwable);
}
Custom Theme
自定义RecoveryActivity的主题,需重写以下styles属性:
<color name="recovery_colorPrimary">#2E2E36</color>
<color name="recovery_colorPrimaryDark">#2E2E36</color>
<color name="recovery_colorAccent">#BDBDBD</color>
<color name="recovery_background">#3C4350</color>
<color name="recovery_textColor">#FFFFFF</color>
<color name="recovery_textColor_sub">#C6C6C6</color>
Crash File Path
{SDCard Dir}/Android/data/{packageName}/files/recovery_crash/
Update history
VERSION-0.0.5——支持静默恢复VERSION-0.0.6——加强静默恢复模式的保护VERSION-0.0.7——添加混淆配置VERSION-0.0.8——增加可配置不需要恢复的Activity,方法:skip()VERSION-0.0.9——更新UI和解决一些问题VERSION-0.1.0——异常传递的优化,可在任意位置初始化Recovery框架,发布正式版本VERSION-0.1.3——增加no-op包VERSION-0.1.4——更新默认主题.VERSION-0.1.5——fix 8.0+ hook bugVERSION-0.1.6——updateVERSION-1.0.0——修复8.0上兼容性问题
About
- Blog:https://zhengxiaoyong.com
- Wechat:

LICENSE
Copyright 2016 zhengxiaoyong
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.