当前位置:网站首页>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))
}
边栏推荐
- 4-33--4-35
- Yolov5进阶之八 高低版本格式转换问题
- Joomla! CMS 3.0~3.4.6 RCE
- [ue4] geometry drawing pipeline
- Zzuli:1045 numerical statistics
- 【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
- Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
- [opengl] pre bake using computational shaders
- NOI OPENJUDGE 1.4(15)
- [combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
猜你喜欢
[opengl] advanced chapter of texture - principle of flowmap
QT program font becomes larger on computers with different resolutions, overflowing controls
[graphics] hair simulation in tressfx
[engine development] in depth GPU and rendering optimization (basic)
[ue4] material and shader permutation
Use of form text box (I) select text
ASTC texture compression (adaptive scalable texture compression)
Byte practice surface longitude
Composite type (custom type)
什么是embedding(把物体编码为一个低维稠密向量),pytorch中nn.Embedding原理及使用
随机推荐
Yolov5 advanced seven target tracking latest environment construction (II)
[graphics] adaptive shadow map
2021-10-16 initial programming
Center and drag linked global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
C language to implement a password manager (under update)
什么是embedding(把物体编码为一个低维稠密向量),pytorch中nn.Embedding原理及使用
Class part2
QT - draw something else
Besides lying flat, what else can a 27 year old do in life?
Pytoch deep learning and target detection practice notes
C language to realize mine sweeping
【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer
Mmdetection learning rate and batch_ Size relationship
Simulation of LS -al command in C language
Zzuli:1057 prime number determination
Remote server background hangs nohup
5.4-5.5
Zzuli:1058 solving inequalities
Zzuli:1047 logarithmic table
NOI OPENJUDGE 1.4(15)