当前位置:网站首页>App global exception capture
App global exception capture
2022-07-03 15:00:00 【Mo Mo 0830】
App Exception global capture , Prevent application crash fall ( Not against ANR).
/** * Exception trapping * */
public class NeverCrash {
private CrashHandler mCrashHandler;
private static NeverCrash mInstance;
private NeverCrash(){
}
private static NeverCrash getInstance(){
if(mInstance == null){
synchronized (NeverCrash.class){
if(mInstance == null){
mInstance = new NeverCrash();
}
}
}
return mInstance;
}
public static void init(CrashHandler crashHandler){
getInstance().setCrashHandler(crashHandler);
}
private void setCrashHandler(CrashHandler crashHandler){
mCrashHandler = crashHandler;
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
for (;;) {
try {
Looper.loop();
} catch (Throwable e) {
if (mCrashHandler != null) {
// Catch exception handling
mCrashHandler.uncaughtException(Looper.getMainLooper().getThread(), e);
}
}
}
}
});
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
if(mCrashHandler!=null){
// Catch exception handling
mCrashHandler.uncaughtException(t,e);
}
}
});
}
public interface CrashHandler{
void uncaughtException(Thread t,Throwable e);
}
}
stay application Use in :
NeverCrash.init {
t, e ->
Log.d(TAG, Log.getStackTraceString(e))
}
边栏推荐
- [Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
- Série yolov5 (i) - - netron, un outil de visualisation de réseau
- Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
- 5.2-5.3
- Remote server background hangs nohup
- C language to implement a password manager (under update)
- [opengl] face pinching system
- NOI OPENJUDGE 1.4(15)
- Yolov5 advanced nine target tracking example 1
- 406. 根据身高重建队列
猜你喜欢
随机推荐
Zero copy underlying analysis
CentOS7部署哨兵Redis(带架构图,清晰易懂)
Yolov5进阶之七目标追踪最新环境搭建(二)
【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer
Dllexport and dllimport
[opengl] pre bake using computational shaders
Yolov5系列(一)——網絡可視化工具netron
Yolov5进阶之九 目标追踪实例1
Piwigo 2.7.1 sqli learning
Global and Chinese market of marketing automation 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for ionization equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Zzuli:1059 highest score
什么是embedding(把物体编码为一个低维稠密向量),pytorch中nn.Embedding原理及使用
TPS61170QDRVRQ1
4-24--4-28
Unity hierarchical bounding box AABB tree
Leetcode sword offer find the number I (nine) in the sorted array
Zzuli:1057 prime number determination
Zzuli: cumulative sum of 1050 factorials
Global and Chinese markets for infrared solutions (for industrial, civil, national defense and security applications) 2022-2028: Research Report on technology, participants, trends, market size and sh