├── .gitignore ├── LICENSE ├── README-Chinese.md ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zxy │ │ └── recovery │ │ └── test │ │ ├── App.java │ │ ├── BaseActivity.java │ │ ├── MainActivity.java │ │ ├── MyCrashHandler.java │ │ ├── TestActivity.java │ │ └── TestActivity2.java │ └── res │ ├── layout │ ├── activity_main.xml │ ├── activity_test.xml │ └── activity_test2.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-v21 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── recovery-no-op ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zxy │ │ └── recovery │ │ ├── callback │ │ └── RecoveryCallback.java │ │ └── core │ │ └── Recovery.java │ └── res │ └── values │ └── strings.xml ├── recovery.jpg ├── recovery ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zxy │ │ └── recovery │ │ ├── callback │ │ ├── RecoveryActivityLifecycleCallback.java │ │ └── RecoveryCallback.java │ │ ├── core │ │ ├── ActivityManagerDelegate.java │ │ ├── ActivityStackCompat.java │ │ ├── ApplicationLoader.java │ │ ├── CrashData.java │ │ ├── Recovery.java │ │ ├── RecoveryActivity.java │ │ ├── RecoveryComponentHook.java │ │ ├── RecoveryHandler.java │ │ ├── RecoveryService.java │ │ └── RecoveryStore.java │ │ ├── exception │ │ ├── RecoveryException.java │ │ └── ReflectException.java │ │ └── tools │ │ ├── DefaultHandlerUtil.java │ │ ├── RecoveryLog.java │ │ ├── RecoverySharedPrefsUtil.java │ │ ├── RecoverySilentSharedPrefsUtil.java │ │ ├── RecoveryUtil.java │ │ ├── Reflect.java │ │ └── SharedPreferencesCompat.java │ └── res │ ├── drawable-xhdpi │ └── ic_recovery_page.png │ ├── drawable │ └── recovery_default_btn_selector.xml │ ├── layout │ ├── recovery_activity_recover.xml │ └── recovery_layout_debug.xml │ ├── menu │ ├── recovery_menu.xml │ └── recovery_menu_sub.xml │ ├── values-en │ └── strings.xml │ ├── values-v19 │ └── styles.xml │ ├── values-v21 │ └── styles.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Android template 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # Intellij 38 | *.iml 39 | .idea/ 40 | 41 | # Keystore files 42 | *.jks 43 | 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README-Chinese.md: -------------------------------------------------------------------------------- 1 | # **Recovery** 2 | A crash recovery framework! 3 | 4 | ---- 5 | 6 | [ ![Download](https://api.bintray.com/packages/sunzxyong/maven/Recovery/images/download.svg) ](https://bintray.com/sunzxyong/maven/Recovery/_latestVersion) ![build](https://img.shields.io/badge/build-passing-blue.svg) [![License](https://img.shields.io/hexpm/l/plug.svg)](https://github.com/Sunzxyong/Recovery/blob/master/LICENSE) 7 | 8 | [英文文档](https://github.com/Sunzxyong/Recovery/blob/master/README.md) 9 | 10 | # **Introduce** 11 | 12 | [博客介绍](http://zhengxiaoyong.com/2016/09/05/Android%E8%BF%90%E8%A1%8C%E6%97%B6Crash%E8%87%AA%E5%8A%A8%E6%81%A2%E5%A4%8D%E6%A1%86%E6%9E%B6-Recovery) 13 | 14 | “Recovery”帮助你自动处理程序在运行时的Crash,它含有以下几点功能 15 | 16 | * 自动恢复Activity Stack和数据 17 | * 支持只恢复栈顶Activity 18 | * Crash信息的显示与保存 19 | * 应用重启或者清空缓存 20 | * 一分钟内两次恢复失败不再恢复而进行重启应用 21 | 22 | # **Art** 23 | ![recovery](http://7xswxf.com2.z0.glb.qiniucdn.com//blog/recovery.jpg) 24 | 25 | # **Usage** 26 | ## **Reference** 27 | **Gradle** 28 | 29 | ``` 30 | implementation 'com.zxy.android:recovery:1.0.0' 31 | ``` 32 | 33 | 或者 34 | 35 | ```gradle 36 | debugImplementation 'com.zxy.android:recovery:1.0.0' 37 | releaseImplementation 'com.zxy.android:recovery-no-op:1.0.0' 38 | ``` 39 | 40 | 41 | **Maven** 42 | 43 | ``` 44 | 45 | com.zxy.android 46 | recovery 47 | 1.0.0 48 | pom 49 | 50 | ``` 51 | ## **Init** 52 | 你可以使用类似如下初始化代码在你自定义的Application中进行初始化: 53 | 54 | ```java 55 | Recovery.getInstance() 56 | .debug(true) 57 | .recoverInBackground(false) 58 | .recoverStack(true) 59 | .mainPage(MainActivity.class) 60 | .recoverEnabled(true) 61 | .callback(new MyCrashCallback()) 62 | .silent(false, Recovery.SilentMode.RECOVER_ACTIVITY_STACK) 63 | .skip(TestActivity.class) 64 | .init(this); 65 | ``` 66 | 67 | 如果你不想在应用发生Crash时显示RecoveryActivity,你可以使用静默恢复来进行无界面的恢复你的应用,那么请使用类似如下初始化代码在你自定义的Application中进行初始化: 68 | 69 | ```java 70 | Recovery.getInstance() 71 | .debug(true) 72 | .recoverInBackground(false) 73 | .recoverStack(true) 74 | .mainPage(MainActivity.class) 75 | .recoverEnabled(true) 76 | .callback(new MyCrashCallback()) 77 | .silent(false, Recovery.SilentMode.RECOVER_ACTIVITY_STACK) 78 | .skip(TestActivity.class) 79 | .init(this); 80 | ``` 81 | 82 | 如果你仅仅需要在开发时显示RecoveryActivity界面来获取debug数据,而在线上版本不显示,那么可以设置`recoverEnabled(false);` 83 | 84 | ## **Arguments** 85 | 86 | | Argument | Type | Function | 87 | | :-: | :-: | :-: | 88 | | debug | boolean | 是否开启debug模式 | 89 | | recoverInBackgroud | boolean | 当应用在后台时发生Crash,是否需要进行恢复 | 90 | | recoverStack | boolean | 是否恢复整个Activity Stack,否则将恢复栈顶Activity | 91 | | mainPage | Class | 回退的界面 | 92 | | callback | RecoveryCallback | 发生Crash时的回调 | 93 | | silent | boolean,SilentMode | 是否使用静默恢复,如果设置为true的情况下,那么在发生Crash时将不显示RecoveryActivity界面来进行恢复,而是自动的恢复Activity的堆栈和数据,也就是无界面恢复 | 94 | 95 | **SilentMode** 96 | > 1. RESTART - 重启应用 97 | > 2. RECOVER_ACTIVITY_STACK - 恢复Activity堆栈 98 | > 3. RECOVER_TOP_ACTIVITY - 恢复栈顶Activity 99 | > 4. RESTART_AND_CLEAR - 重启应用并清空缓存数据 100 | 101 | ## **Callback** 102 | 103 | ``` 104 | public interface RecoveryCallback { 105 | 106 | void stackTrace(String stackTrace); 107 | 108 | void cause(String cause); 109 | 110 | void exception(String throwExceptionType, String throwClassName, String throwMethodName, int throwLineNumber); 111 | 112 | void throwable(Throwable throwable); 113 | } 114 | ``` 115 | 116 | ## **Custom Theme** 117 | 118 | 自定义RecoveryActivity的主题,需重写以下styles属性: 119 | 120 | ``` 121 | #2E2E36 122 | #2E2E36 123 | #BDBDBD 124 | #3C4350 125 | #FFFFFF 126 | #C6C6C6 127 | ``` 128 | ## **Crash File Path** 129 | > {SDCard Dir}/Android/data/{packageName}/files/recovery_crash/ 130 | 131 | ## **Update history** 132 | * `VERSION-0.0.5`——**支持静默恢复** 133 | * `VERSION-0.0.6`——**加强静默恢复模式的保护** 134 | * `VERSION-0.0.7`——**添加混淆配置** 135 | * `VERSION-0.0.8`——**增加可配置不需要恢复的Activity,方法:skip()** 136 | * `VERSION-0.0.9`——**更新UI和解决一些问题** 137 | * `VERSION-0.1.0`——**异常传递的优化,可在任意位置初始化Recovery框架,发布正式版本** 138 | * `VERSION-0.1.3`——**增加no-op包** 139 | * `VERSION-0.1.4`——**更新默认主题.** 140 | * `VERSION-0.1.5`——**fix 8.0+ hook bug** 141 | * `VERSION-0.1.6`——**update** 142 | * `VERSION-1.0.0`——**修复8.0上兼容性问题** 143 | 144 | ## **About** 145 | * **Blog**:[https://zhengxiaoyong.com](https://zhengxiaoyong.com) 146 | * **Wechat**: 147 | 148 | ![](https://raw.githubusercontent.com/Sunzxyong/ImageRepository/master/qrcode.jpg) 149 | 150 | # **LICENSE** 151 | 152 | ``` 153 | Copyright 2016 zhengxiaoyong 154 | 155 | Licensed under the Apache License, Version 2.0 (the "License"); 156 | you may not use this file except in compliance with the License. 157 | You may obtain a copy of the License at 158 | 159 | http://www.apache.org/licenses/LICENSE-2.0 160 | 161 | Unless required by applicable law or agreed to in writing, software 162 | distributed under the License is distributed on an "AS IS" BASIS, 163 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 164 | See the License for the specific language governing permissions and 165 | limitations under the License. 166 | ``` 167 | 168 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **Recovery** 2 | A crash recovery framework! 3 | 4 | ---- 5 | 6 | [ ![Download](https://api.bintray.com/packages/sunzxyong/maven/Recovery/images/download.svg) ](https://bintray.com/sunzxyong/maven/Recovery/_latestVersion) ![build](https://img.shields.io/badge/build-passing-blue.svg) [![License](https://img.shields.io/hexpm/l/plug.svg)](https://github.com/Sunzxyong/Recovery/blob/master/LICENSE) 7 | 8 | [中文文档](https://github.com/Sunzxyong/Recovery/blob/master/README-Chinese.md) 9 | 10 | # **Introduction** 11 | 12 | [Blog entry with introduction](http://zhengxiaoyong.com/2016/09/05/Android%E8%BF%90%E8%A1%8C%E6%97%B6Crash%E8%87%AA%E5%8A%A8%E6%81%A2%E5%A4%8D%E6%A1%86%E6%9E%B6-Recovery) 13 | 14 | “Recovery” can help you to automatically handle application crash in runtime. It provides you with following functionality: 15 | 16 | * Automatic recovery activity with stack and data; 17 | * Ability to recover to the top activity; 18 | * A way to view and save crash info; 19 | * Ability to restart and clear the cache; 20 | * Allows you to do a restart instead of recovering if failed twice in one minute. 21 | 22 | # **Art** 23 | ![recovery](http://7xswxf.com2.z0.glb.qiniucdn.com//blog/recovery.jpg) 24 | 25 | # **Usage** 26 | ## **Installation** 27 | **Using Gradle** 28 | 29 | ```gradle 30 | implementation 'com.zxy.android:recovery:1.0.0' 31 | ``` 32 | 33 | or 34 | 35 | ```gradle 36 | debugImplementation 'com.zxy.android:recovery:1.0.0' 37 | releaseImplementation 'com.zxy.android:recovery-no-op:1.0.0' 38 | ``` 39 | 40 | 41 | **Using Maven** 42 | 43 | ```xml 44 | 45 | com.zxy.android 46 | recovery 47 | 1.0.0 48 | pom 49 | 50 | ``` 51 | 52 | ## **Initialization** 53 | You can use this code sample to initialize Recovery in your application: 54 | 55 | ```java 56 | Recovery.getInstance() 57 | .debug(true) 58 | .recoverInBackground(false) 59 | .recoverStack(true) 60 | .mainPage(MainActivity.class) 61 | .recoverEnabled(true) 62 | .callback(new MyCrashCallback()) 63 | .silent(false, Recovery.SilentMode.RECOVER_ACTIVITY_STACK) 64 | .skip(TestActivity.class) 65 | .init(this); 66 | ``` 67 | 68 | If you don't want to show the RecoveryActivity when the application crash in runtime,you can use silence recover to restore your application. 69 | 70 | You can use this code sample to initialize Recovery in your application: 71 | 72 | ```java 73 | Recovery.getInstance() 74 | .debug(true) 75 | .recoverInBackground(false) 76 | .recoverStack(true) 77 | .mainPage(MainActivity.class) 78 | .recoverEnabled(true) 79 | .callback(new MyCrashCallback()) 80 | .silent(true, Recovery.SilentMode.RECOVER_ACTIVITY_STACK) 81 | .skip(TestActivity.class) 82 | .init(this); 83 | ``` 84 | 85 | If you only need to display 'RecoveryActivity' page in development to obtain the debug data, and in the online version does not display, you can set up `recoverEnabled(false);` 86 | 87 | ## **Arguments** 88 | 89 | | Argument | Type | Function | 90 | | :-: | :-: | :-: | 91 | | debug | boolean | Whether to open the debug mode | 92 | | recoverInBackgroud | boolean | When the App in the background, whether to restore the stack | 93 | | recoverStack | boolean | Whether to restore the activity stack, or to restore the top activity | 94 | | mainPage | Class | Initial page activity | 95 | | callback | RecoveryCallback | Crash info callback | 96 | | silent | boolean,SilentMode | Whether to use silence recover,if true it will not display RecoveryActivity and restore the activity stack automatically | 97 | 98 | **SilentMode** 99 | > 1. RESTART - Restart App 100 | > 2. RECOVER_ACTIVITY_STACK - Restore the activity stack 101 | > 3. RECOVER_TOP_ACTIVITY - Restore the top activity 102 | > 4. RESTART_AND_CLEAR - Restart App and clear data 103 | 104 | ## **Callback** 105 | 106 | ```java 107 | public interface RecoveryCallback { 108 | 109 | void stackTrace(String stackTrace); 110 | 111 | void cause(String cause); 112 | 113 | void exception( 114 | String throwExceptionType, 115 | String throwClassName, 116 | String throwMethodName, 117 | int throwLineNumber 118 | ); 119 | 120 | void throwable(Throwable throwable); 121 | } 122 | ``` 123 | 124 | ## **Custom Theme** 125 | 126 | You can customize UI by setting these properties in your styles file: 127 | 128 | ```xml 129 | #2E2E36 130 | #2E2E36 131 | #BDBDBD 132 | #3C4350 133 | #FFFFFF 134 | #C6C6C6 135 | ``` 136 | 137 | ## **Crash File Path** 138 | > {SDCard Dir}/Android/data/{packageName}/files/recovery_crash/ 139 | 140 | ---- 141 | ## **Update history** 142 | * `VERSION-0.0.5`——**Support silent recovery** 143 | * `VERSION-0.0.6`——**Strengthen the protection of silent restore mode** 144 | * `VERSION-0.0.7`——**Add confusion configuration** 145 | * `VERSION-0.0.8`——**Add the skip Activity features,method:skip()** 146 | * `VERSION-0.0.9`——**Update the UI and solve some problems** 147 | * `VERSION-0.1.0`——**Optimization of crash exception delivery, initial Recovery framework can be in any position, release the official version-0.1.0** 148 | * `VERSION-0.1.3`——**Add 'no-op' support** 149 | * `VERSION-0.1.4`——**update default theme** 150 | * `VERSION-0.1.5`——**fix 8.0+ hook bug** 151 | * `VERSION-0.1.6`——**update** 152 | * `VERSION-1.0.0`——**Fix 8.0 compatibility issue** 153 | 154 | ## **About** 155 | * **Blog**:[https://zhengxiaoyong.com](https://zhengxiaoyong.com) 156 | * **Wechat**: 157 | 158 | ![](https://raw.githubusercontent.com/Sunzxyong/ImageRepository/master/qrcode.jpg) 159 | # **LICENSE** 160 | 161 | ``` 162 | Copyright 2016 zhengxiaoyong 163 | 164 | Licensed under the Apache License, Version 2.0 (the "License"); 165 | you may not use this file except in compliance with the License. 166 | You may obtain a copy of the License at 167 | 168 | http://www.apache.org/licenses/LICENSE-2.0 169 | 170 | Unless required by applicable law or agreed to in writing, software 171 | distributed under the License is distributed on an "AS IS" BASIS, 172 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 173 | See the License for the specific language governing permissions and 174 | limitations under the License. 175 | ``` 176 | 177 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | 6 | resourcePrefix "" 7 | defaultConfig { 8 | applicationId "com.zxy.recovery.test" 9 | minSdkVersion 14 10 | targetSdkVersion 26 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | lintOptions { 21 | abortOnError false 22 | } 23 | 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(include: ['*.jar'], dir: 'libs') 28 | 29 | // debugCompile 'com.zxy.android:recovery:0.1.5' 30 | // releaseCompile 'com.zxy.android:recovery-no-op:0.1.5' 31 | implementation 'com.android.support:appcompat-v7:25.2.0' 32 | implementation 'com.android.support:design:25.2.0' 33 | debugImplementation project(':recovery') 34 | releaseImplementation project(':recovery-no-op') 35 | } 36 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Sunzxyong/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/zxy/recovery/test/App.java: -------------------------------------------------------------------------------- 1 | package com.zxy.recovery.test; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.util.Log; 6 | 7 | import com.zxy.recovery.callback.RecoveryCallback; 8 | import com.zxy.recovery.core.Recovery; 9 | 10 | /** 11 | * Created by zhengxiaoyong on 16/8/26. 12 | */ 13 | public class App extends Application { 14 | @Override 15 | protected void attachBaseContext(Context base) { 16 | super.attachBaseContext(base); 17 | } 18 | 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | 23 | Log.e("zxy", "Recovery: init"); 24 | Recovery.getInstance() 25 | .debug(true) 26 | .recoverInBackground(false) 27 | .recoverStack(true) 28 | .mainPage(MainActivity.class) 29 | .recoverEnabled(true) 30 | .callback(new MyCrashCallback()) 31 | .silent(false, Recovery.SilentMode.RECOVER_ACTIVITY_STACK) 32 | .skip(TestActivity.class) 33 | .init(this); 34 | 35 | MyCrashHandler.register(); 36 | 37 | } 38 | 39 | static final class MyCrashCallback implements RecoveryCallback { 40 | @Override 41 | public void stackTrace(String exceptionMessage) { 42 | Log.e("zxy", "exceptionMessage:" + exceptionMessage); 43 | } 44 | 45 | @Override 46 | public void cause(String cause) { 47 | Log.e("zxy", "cause:" + cause); 48 | } 49 | 50 | @Override 51 | public void exception(String exceptionType, String throwClassName, String throwMethodName, int throwLineNumber) { 52 | Log.e("zxy", "exceptionClassName:" + exceptionType); 53 | Log.e("zxy", "throwClassName:" + throwClassName); 54 | Log.e("zxy", "throwMethodName:" + throwMethodName); 55 | Log.e("zxy", "throwLineNumber:" + throwLineNumber); 56 | } 57 | 58 | @Override 59 | public void throwable(Throwable throwable) { 60 | 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/zxy/recovery/test/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.zxy.recovery.test; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | /** 8 | * Created by zhengxiaoyong on 16/8/30. 9 | */ 10 | public class BaseActivity extends AppCompatActivity { 11 | @Override 12 | protected void onCreate(@Nullable Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | } 15 | 16 | @Override 17 | protected void onStart() { 18 | super.onStart(); 19 | // getWindow().getDecorView().post(new Runnable() { 20 | // @Override 21 | // public void run() { 22 | // int count = ActivityStackCompat.getActivityCount(Recovery.getInstance().getContext()); 23 | // Log.e("zxy", "realCount: " + count); 24 | // String baseActivity = ActivityStackCompat.getBaseActivityName(Recovery.getInstance().getContext()); 25 | // Log.e("zxy", "realBaseActivityName: " + baseActivity); 26 | // } 27 | // }); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/zxy/recovery/test/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zxy.recovery.test; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | public class MainActivity extends BaseActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_main); 14 | } 15 | 16 | public void onClick(View view) { 17 | if (view.getId() == R.id.btn) { 18 | Activity activity = null; 19 | activity.finish(); 20 | } else if (view.getId() == R.id.btn2) { 21 | Intent intent = new Intent(MainActivity.this, TestActivity.class); 22 | startActivity(intent); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/zxy/recovery/test/MyCrashHandler.java: -------------------------------------------------------------------------------- 1 | package com.zxy.recovery.test; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * Created by zhengxiaoyong on 2017/1/16. 7 | */ 8 | public class MyCrashHandler implements Thread.UncaughtExceptionHandler { 9 | 10 | private Thread.UncaughtExceptionHandler mUncaughtExceptionHandler; 11 | 12 | public MyCrashHandler() { 13 | mUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); 14 | } 15 | 16 | @Override 17 | public void uncaughtException(Thread t, Throwable e) { 18 | Log.e("zxy", "myCrashHandler..."); 19 | mUncaughtExceptionHandler.uncaughtException(t, e); 20 | } 21 | 22 | 23 | public static void register() { 24 | Thread.setDefaultUncaughtExceptionHandler(new MyCrashHandler()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/zxy/recovery/test/TestActivity.java: -------------------------------------------------------------------------------- 1 | package com.zxy.recovery.test; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.view.Window; 8 | 9 | public class TestActivity extends BaseActivity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | requestWindowFeature(Window.FEATURE_NO_TITLE); 15 | setContentView(R.layout.activity_test); 16 | // new Thread(new Runnable() { 17 | // int i = 0; 18 | // 19 | // @Override 20 | // public void run() { 21 | // while (true) { 22 | // if (i == 3) { 23 | // Activity activity = null; 24 | // activity.finish(); 25 | // } 26 | // try { 27 | // Thread.sleep(1000); 28 | // } catch (InterruptedException e) { 29 | // e.printStackTrace(); 30 | // } 31 | // i++; 32 | // } 33 | // } 34 | // }).start(); 35 | } 36 | 37 | @Override 38 | protected void onResume() { 39 | super.onResume(); 40 | } 41 | 42 | public void onClick(View view) { 43 | if (view.getId() == R.id.btn) { 44 | Activity activity = null; 45 | activity.finish(); 46 | } else if (view.getId() == R.id.btn2) { 47 | Intent intent = new Intent(TestActivity.this, TestActivity2.class); 48 | startActivity(intent); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/zxy/recovery/test/TestActivity2.java: -------------------------------------------------------------------------------- 1 | package com.zxy.recovery.test; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | public class TestActivity2 extends BaseActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_test2); 14 | } 15 | 16 | public void onClick(View view) { 17 | if (view.getId() == R.id.btn) { 18 | Activity activity = null; 19 | activity.finish(); 20 | } else if (view.getId() == R.id.btn2) { 21 | startActivity(new Intent(this, MainActivity.class)); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 18 | 19 | 24 | 25 |