android程序崩溃框架—CustomActivityOnCrash,零基础学android开发

android程序崩溃框架—CustomActivityOnCrash,零基础学android开发,第1张

android程序崩溃框架—CustomActivityOnCrash,零基础学android开发

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;

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5709932.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存