setDefaultUncaughtExceptionHandler makes app crash silently

前端 未结 1 1079
慢半拍i
慢半拍i 2021-01-13 19:37

CustomExceptionHandler

public class CustomExceptionHandler implements UncaughtExceptionHandler {

private Context ctx;
private ContentResolv         


        
相关标签:
1条回答
  • 2021-01-13 20:06

    You can add the following at the end of your exception handler to get the "unfortunately has stopped" dialog:

    System.exit(1);
    

    However, this will cause the process to terminate which means that your AsyncTask will not run to completion.

    In any case, I would doubt that your code will run reliably anyway if you are in an uncaughtExceptionHandler, because you have no idea what the state of your application is. It might work, and it might not. What you could also try is to create a new Thread in your uncaughtExceptionHandler and have that thread sleep for a little while and then terminate the application using System.exit(). That may give your AsyncTask enough time to run to completion.

    0 讨论(0)
提交回复
热议问题