开发者

How to show a dialog for an exception while halting the rest of the program flow?

I have thought out an IMHO neat way of handling checked Exceptions, like so:

protected void handleException(Throwable e, int messageResourceId, ExceptionReaction reaction) {...}

which would be part of the app's BaseActivity (thus usable in all Activities). Within this method I intend to show a dialog with the given message string and an OK button, and afterwards do something to react individually to the Exception (restart the activity, log the user out, reset database,...). However, the dialog is started on the UI thread non-blockingly, and the Activities having called handleException(...) would just continue execution while the dialog is shown - which sucks, because something most probably has gone very wrong and e.g. an activity-restart might be needed.

Note that the UI thread can't be put to开发者_C百科 sleep or wait, since then the OK button in the dialog would not work at all.

Has anybody got an idea how to achieve this?


Has anybody got an idea how to achieve this?

Put your "do something to react individually to the Exception" in the dialog close-button handler, such as via a final Runnable.


Have you tried UncaughtExceptionHandler?

Refer this doc Thread.UncaughtExceptionHandler

Implement this interface and do the handling stuff in the callback uncaughtException(Thread thread, Throwable ex)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜