安卓UncaughtExceptionHandler的实例化一个AlertDialog休息 [英] Android UncaughtExceptionHandler that instantiates an AlertDialog breaks
问题描述
正如标题所说,我有一个的UncaughtExceptionHandler
在被设置为默认我的自定义应用程序类设置时,我的应用程序启动。
不过,虽然没有在文档中我已阅读,你不能实例化一个对话框
使用 MyApplication.this
或 getApplicationContext()
。当我尝试这样做,我收到了
窗口管理器,$ BadTokenException ...
我需要一种替代方法。我曾经想过做一个新的活动,以弥补这一点,但宁可让它成为一个 AlertDialog
。
有没有一种方法可以让我得到一个有效的范围内,以我的的UncaughtExceptionHandler
从内所有MyApplication
类?
我已阅读,你不能使用MyApplication.this或对话实例getApplicationContext
正确的。应用程序上下文不用于构建用户界面特别有用。
我曾想过做一个新的活动,以弥补这一点,但宁可让它成为一个AlertDialog。
这是 AlertDialog
是不可能在这种情况下。对于初学者来说,只有一个活动可以打开一个对话框,并没有你的活动可能正在运行(例如,坠毁在一个后台服务)和有效的(例如,你有一个,但它是一个崩溃)。
编辑:固定previous段清理混乱
As the title says, I have an UncaughtExceptionHandler
set in my custom application class that gets set as the default when my application starts.
However, while not in the documentation I have read that you cannot instantiate a Dialog
using MyApplication.this
or getApplicationContext()
. When I try to do it, I get a
WindowManager$BadTokenException...
I need an alternative. I have thought of making a new activity to compensate for this but would rather have it be an AlertDialog
.
Is there a way I can get a valid context to my UncaughtExceptionHandler
from inside MyApplication
class?
I have read that you cannot instantiate a Dialog using MyApplication.this or getApplicationContext
Correct. The Application context is not especially useful for constructing UIs.
I have thought of making a new activity to compensate for this but would rather have it be an AlertDialog.
An AlertDialog
is impossible in this case. For starters, only an activity can open a dialog, and none of your activities may be running (e.g., crash in a background service) and valid (e.g., you had one, but it's the one that crashed).
EDIT: Fixed previous paragraph to clear up confusion
这篇关于安卓UncaughtExceptionHandler的实例化一个AlertDialog休息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!