Added: Add functions that can be used by non main threads to set CrashHandler as the UncaughtExceptionHandler

This commit is contained in:
agnostic-apollo
2022-04-17 05:56:35 +05:00
parent 6b60adc079
commit 9c7ec0cebd
2 changed files with 27 additions and 1 deletions

View File

@@ -50,6 +50,20 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
}
}
/**
* Set uncaught crash handler of current non-main thread to {@link CrashHandler}.
*/
public static void setCrashHandler(@NonNull final Context context, @NonNull final CrashHandlerClient crashHandlerClient) {
Thread.currentThread().setUncaughtExceptionHandler(new CrashHandler(context, crashHandlerClient, false));
}
/**
* Get {@link CrashHandler} instance that can be set as uncaught crash handler of a non-main thread.
*/
public static CrashHandler getCrashHandler(@NonNull final Context context, @NonNull final CrashHandlerClient crashHandlerClient) {
return new CrashHandler(context, crashHandlerClient, false);
}
/**
* Log a crash in the crash log file at path returned by {@link CrashHandlerClient#getCrashLogFilePath(Context)}.
*