当前位置:网站首页>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))
}
边栏推荐
- Zzuli:1054 monkeys eat peaches
- Unity hierarchical bounding box AABB tree
- Remote server background hangs nohup
- NOI OPENJUDGE 1.4(15)
- [ue4] material and shader permutation
- Fundamentals of PHP deserialization
- Talking about part of data storage in C language
- Qt—绘制其他东西
- Global and Chinese market of Bus HVAC systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
猜你喜欢

Yolov5 series (I) -- network visualization tool netron
![[opengl] advanced chapter of texture - principle of flowmap](/img/dd/6208122fcc578caaf098301b185e03.jpg)
[opengl] advanced chapter of texture - principle of flowmap

dllexport和dllimport

Besides lying flat, what else can a 27 year old do in life?

High quality workplace human beings must use software to recommend, and you certainly don't know the last one

Byte practice surface longitude

Unity hierarchical bounding box AABB tree
![[graphics] real shading in Unreal Engine 4](/img/8d/53775c7570c5578f4fe985592bb305.jpg)
[graphics] real shading in Unreal Engine 4

PS tips - draw green earth with a brush

Devaxpress: range selection control rangecontrol uses
随机推荐
Leetcode sword offer find the number I (nine) in the sorted array
Detailed explanation of four modes of distributed transaction (Seata)
C language fcntl function
Zzuli: sum of 1051 square roots
Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
Yolov5 advanced nine target tracking example 1
Zzuli: cumulative sum of 1050 factorials
4-24--4-28
Yolov5进阶之七目标追踪最新环境搭建(二)
C string format (decimal point retention / decimal conversion, etc.)
Zzuli:1056 lucky numbers
零拷贝底层剖析
The latest M1 dedicated Au update Adobe audit CC 2021 Chinese direct installation version has solved the problems of M1 installation without flash back!
Yolov5进阶之八 高低版本格式转换问题
[graphics] hair simulation in tressfx
Global and Chinese market of trimethylamine 2022-2028: Research Report on technology, participants, trends, market size and share
Mmdetection learning rate and batch_ Size relationship
TPS61170QDRVRQ1
To improve efficiency or increase costs, how should developers understand pair programming?
Zzuli:1058 solving inequalities