public class CrashApp extends Application {

  public static final String TAG = "CrashApp";

  @Override
  protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
new Handler(getMainLooper()).post(new Runnable() { @Override public void run() { while (true) { try { Looper.loop();  //try-catch主线程的所有异常;Looper.loop()内部是一个死循环,出现异常时才会退出,所以这里使用while(true)。 } catch (Throwable e) { Log.d(TAG, "Looper.loop(): " + e.getMessage()); } } } }); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) {  //try-catch子线程的所有异常。 Log.d(TAG, "UncaughtExceptionHandler: " + e.getMessage()); } });
} @Override
public void onCreate() { super.onCreate(); } }

<application android:name=".CrashApp">
</application>
 

 

相关文章:

  • 2021-11-11
  • 2022-12-23
  • 2021-11-13
  • 2021-07-28
  • 2022-12-23
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-08-08
  • 2022-12-23
相关资源
相似解决方案