Skip to content

Commit b5d030c

Browse files
committed
see 04/10 log
1 parent 46a5a9c commit b5d030c

File tree

8 files changed

+41
-29
lines changed

8 files changed

+41
-29
lines changed

README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
4343

44-
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.9-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.10-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

4747
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen
4141

4242
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
4343

44-
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.9-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.10-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

4747
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

app/src/main/java/com/blankj/androidutilcode/UtilsApp.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,15 @@ public void initLog() {
6666
.setConsoleFilter(LogUtils.V)// log 的控制台过滤器,和 logcat 过滤器同理,默认 Verbose
6767
.setFileFilter(LogUtils.V)// log 文件过滤器,和 logcat 过滤器同理,默认 Verbose
6868
.setStackDeep(1);// log 栈深度,默认为 1
69-
new Thread(new Runnable() {
70-
@Override
71-
public void run() {
72-
LogUtils.d(config.toString());
73-
}
74-
}).start();
75-
69+
LogUtils.d(config.toString());
7670
}
7771

7872
@SuppressLint("MissingPermission")
7973
private void initCrash() {
8074
CrashUtils.init(new CrashUtils.OnCrashListener() {
8175
@Override
82-
public void onCrash(Throwable e) {
83-
e.printStackTrace();
76+
public void onCrash(String crashInfo, Throwable e) {
77+
LogUtils.e(crashInfo);
8478
restartApp();
8579
}
8680
});

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ ext {
3333
min_sdk_version = 14
3434
target_sdk_version = 27
3535

36-
version_code = 1_013_009
37-
version_name = '1.13.9'// E.g 1.9.72 => 1,009,072
36+
version_code = 1_013_010
37+
version_name = '1.13.10'// E.g 1.9.72 => 1,009,072
3838

3939
// App dependencies
4040
support_version = '27.1.0'

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* 18/04/10 完善 OnCrashListener 回调崩溃信息,发布 1.13.10 版本
12
* 18/04/09 修复静默安装重载错误,发布 1.13.9 版本
23
* 18/04/08 修复获取栈顶 Activity 链表为空的异常,获取栈顶 Activity 放到 Utils 中,发布 1.13.8 版本
34
* 18/04/06 新增 GsonUtils 及单元测试

utilcode/README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gradle:
44
```groovy
5-
compile 'com.blankj:utilcode:1.13.9'
5+
compile 'com.blankj:utilcode:1.13.10'
66
```
77

88

utilcode/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gradle:
44
```groovy
5-
compile 'com.blankj:utilcode:1.13.9'
5+
compile 'com.blankj:utilcode:1.13.10'
66
```
77

88

utilcode/src/main/java/com/blankj/utilcode/util/CrashUtils.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import android.support.annotation.NonNull;
99
import android.support.annotation.RequiresPermission;
1010

11+
import java.io.BufferedWriter;
1112
import java.io.File;
1213
import java.io.FileWriter;
1314
import java.io.IOException;
1415
import java.io.PrintWriter;
16+
import java.io.StringWriter;
1517
import java.lang.Thread.UncaughtExceptionHandler;
1618
import java.text.Format;
1719
import java.text.SimpleDateFormat;
@@ -85,9 +87,21 @@ public void uncaughtException(final Thread t, final Throwable e) {
8587
}
8688
return;
8789
}
88-
if (sOnCrashListener != null) {
89-
sOnCrashListener.onCrash(e);
90+
91+
StringBuilder sb = new StringBuilder();
92+
sb.append(CRASH_HEAD);
93+
StringWriter sw = new StringWriter();
94+
PrintWriter pw = new PrintWriter(sw);
95+
e.printStackTrace(pw);
96+
Throwable cause = e.getCause();
97+
while (cause != null) {
98+
cause.printStackTrace(pw);
99+
cause = cause.getCause();
90100
}
101+
pw.flush();
102+
sb.append(sw.toString());
103+
final String crashInfo = sb.toString();
104+
91105
Date now = new Date(System.currentTimeMillis());
92106
String fileName = FORMAT.format(now) + ".txt";
93107
final String fullPath = (dir == null ? defaultDir : dir) + fileName;
@@ -98,25 +112,28 @@ public void uncaughtException(final Thread t, final Throwable e) {
98112
sExecutor.execute(new Runnable() {
99113
@Override
100114
public void run() {
101-
PrintWriter pw = null;
115+
BufferedWriter bw = null;
102116
try {
103-
pw = new PrintWriter(new FileWriter(fullPath, false));
104-
pw.write(CRASH_HEAD);
105-
e.printStackTrace(pw);
106-
Throwable cause = e.getCause();
107-
while (cause != null) {
108-
cause.printStackTrace(pw);
109-
cause = cause.getCause();
110-
}
117+
bw = new BufferedWriter(new FileWriter(fullPath, false));
118+
bw.write(crashInfo);
111119
} catch (IOException e) {
112120
e.printStackTrace();
113121
} finally {
114-
if (pw != null) {
115-
pw.close();
122+
if (bw != null) {
123+
try {
124+
bw.close();
125+
} catch (IOException e1) {
126+
e1.printStackTrace();
127+
}
116128
}
117129
}
118130
}
119131
});
132+
133+
if (sOnCrashListener != null) {
134+
sOnCrashListener.onCrash(crashInfo, e);
135+
}
136+
120137
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
121138
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(t, e);
122139
}
@@ -239,6 +256,6 @@ private static boolean isSpace(final String s) {
239256
}
240257

241258
public interface OnCrashListener {
242-
void onCrash(Throwable e);
259+
void onCrash(String crashInfo, Throwable e);
243260
}
244261
}

0 commit comments

Comments
 (0)