Skip to content

Commit

Permalink
崩溃日志文件名字添加版本信息
Browse files Browse the repository at this point in the history
  • Loading branch information
maning committed May 31, 2017
1 parent c17acd1 commit 732b075
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Debug监听程序崩溃日志,直接页面展示崩溃日志列表,方便自
#### 2.在app目录下的build.gradle中添加依赖
``` gradle
dependencies {
compile 'com.github.maning0303:CrashMonitor:V1.0.0'
compile 'com.github.maning0303:CrashMonitor:V1.0.1'
}
```

Expand All @@ -35,10 +35,11 @@ Debug监听程序崩溃日志,直接页面展示崩溃日志列表,方便自

``` java

/** 初始化
* context : 上下文
* isDebug : 是不是Debug状态,true:使用库,false:不会拦截崩溃
*/
/**
* 初始化日志系统
* context : 上下文
* isDebug : 是不是Debug模式,true:崩溃后显示自定义崩溃页面 ;false:关闭应用,不跳转奔溃页面(默认)
*/
MCrashMonitor.init(this, true);

```
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/maning/crashmonitor/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public void onCreate() {
}

private void initCrashMonitor() {
/**
* 初始化日志系统
* context : 上下文
* isDebug : 是不是Debug模式,true:崩溃后显示自定义崩溃页面 ;false:关闭应用,不跳转奔溃页面(默认)
*/
MCrashMonitor.init(this, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class CrashHandler implements UncaughtExceptionHandler {

private Context mContext;

private boolean isDebug = false;

//构造方法私有,防止外部构造多个实例,即采用单例模式
private CrashHandler() {
}
Expand All @@ -58,6 +60,11 @@ public void init(Context context) {
mContext = context.getApplicationContext();
}

public void init(Context context, boolean isDebug) {
init(context);
this.isDebug = isDebug;
}

/**
* 这个是最关键的函数,当程序中有未被捕获的异常,系统将会自动调用#uncaughtException方法
* thread为出现未捕获异常的线程,ex为未捕获的异常,有了这个ex,我们就可以得到异常信息。
Expand All @@ -75,7 +82,9 @@ public void uncaughtException(Thread thread, Throwable ex) {
ex.printStackTrace();

//开启页面
MCrashMonitor.startCrashShowPage(mContext);
if (isDebug) {
MCrashMonitor.startCrashShowPage(mContext);
}

//这里可以弹出自己自定义的程序崩溃页面:然后自己干掉自己;
//如果系统提供了默认的异常处理器,则交给系统去结束我们的程序,否则就由我们自己结束自己
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
public class MCrashMonitor {

public static void init(Context context, boolean isDebug) {
if (isDebug) {
CrashHandler crashHandler = CrashHandler.getInstance();
crashHandler.init(context);
}
CrashHandler crashHandler = CrashHandler.getInstance();
crashHandler.init(context, isDebug);
}

public static void startCrashListPage(Context context) {
Intent intent = new Intent(context.getApplicationContext(), CrashListActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand Down

0 comments on commit 732b075

Please sign in to comment.