开发者

How do I show a dialog after the Thread has encountered an uncaught exception?

开发者 https://www.devze.com 2022-12-13 04:06 出处:网络
I want to detect when an uncaught exception has happened in my Android app. Once detected, I want to display a confirmation dialog

I want to detect when an uncaught exception has happened in my Android app.

Once detected, I want to display a confirmation dialog

How do I get this confirmation dialog to display? When I tried various techniques, the UI is unresponsive and appears to be frozen.

My code responds to this:

new CatchAllExceptionHandler(this) is my custom handler
Thread.setDefaultUncaughtExceptionHandler(new CatchAllExceptionHandler(this));

I have tried these two implementations of CatchAllExceptionHandle开发者_如何学Cr:

  1. Display an Alert dialog
  2. Start an activity that then displays an alert dialog after onCreate

Both these methods failed.

So my question is: How to I get the confirmation dialog to properly display?


You may be attempting to do your UI operations on a non-UI thread. Use any of the available techniques (Handler, Handler#post, View#post, Activity#runOnUiThread, AsyncTask#onPostExecute) to arrange for your UI work to be done on the UI thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消