private static class CustomEventListener implements CustomActivityOnCrash.EventListener {
//程序崩溃回调
@Override
public void onLaunchErrorActivity() {
Log.d(“huangxiaoguo”, “程序崩溃回调”);
}
//重启程序时回调
@Override
public void onRestartAppFromErrorActivity() {
Log.d(“huangxiaoguo”, “重启程序时回调”);
}
//在崩溃提示页面关闭程序时回调
@Override
public void onCloseAppFromErrorActivity() {
Log.d(“huangxiaoguo”, “在崩溃提示页面关闭程序时回调”);
}
}
}
框架自带错误页面我们一般不用!
自定义错误页面
package com.example.customactivityoncrash;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import cat.ereza.customactivityoncrash.CustomActivityOnCrash;
import cat.ereza.customactivityoncrash.config.CaocConfig;
public class MyDefaultErrorActivity extends AppCompatActivity implements View.onClickListener {
private Button mButten;
private Button mClose;
private CaocConfig config;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_default_error);
initView();
initData();
}
private void initData() {
//可以获取到的四个信息:
//将堆栈跟踪作为字符串获取。
String stackString = CustomActivityOnCrash.getStackTraceFromIntent(getIntent());
Log.d(“huangxiaoguo”,“将堆栈跟踪作为字符串获取==>”+stackString);
//获取错误报告的Log信息
String logString = CustomActivityOnCrash.getActivityLogFromIntent(getIntent());
Log.d(“huangxiaoguo”,“获取错误报告的Log信息==>”+logString);
// 获取所有的信息
String allString = CustomActivityOnCrash.getAllErrorDetailsFromIntent(this, getIntent());
Log.d(“huangxiaoguo”,“获取所有的信息==>”+allString);
//获得配置信息,比如设置的程序崩溃显示的页面和重新启动显示的页面等等信息
config = CustomActivityOnCrash.getConfigFromIntent(getIntent());
}
private void initView() {
mButten = (Button) findViewById(R.id.butten);
mButten.setonClickListener(this);
mClose = (Button) findViewById(R.id.close);
mClose.setonClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
default:
break;
case R.id.butten://一键反馈,重新打开
if (config!=null&&config.getRestartActivityClass()!=null){
CustomActivityOnCrash.restartApplication(this,config);
}
break;
case R.id.close://关闭程序
if (config != null) {
CustomActivityOnCrash.closeApplication(this, config);
}
break;
}
}
}
ash.restartApplication(this,config);
}
break;
case R.id.close://关闭程序
if (config != null) {
CustomActivityOnCrash.closeApplication(this, config);
}
break;
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)