ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2022-01-22 15:03:08  阅读:57  来源: 互联网

标签:Log CustomActivityOnCrash void import android config 崩溃


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;

}

}

}


标签:Log,CustomActivityOnCrash,void,import,android,config,崩溃
来源: https://blog.csdn.net/wa32saa/article/details/122637374

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有