从活动启动AlertDialog不AlertDialog

2023-09-06 21:58:00 作者:香蕉裙i

我想在扩展活性的类启动一个警告对话框时没有,但我的GUI线程。我有机会获得我的应用程序上下文,并试图与启动警告对话框,但得到一个错误:

I am trying to launch an alert dialog when not in a class that extends activity, but I am on the GUI thread. I have access to my applications context and attempt to launch the alert dialog with that but get an error:

02-12 00:48:07.412:ERROR / AndroidRuntime(1322):android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null不是一个应用程序

02-12 00:48:07.412: ERROR/AndroidRuntime(1322): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

有谁知道我在这一个做错了吗?

Does anybody know what I am doing wrong on this one?

推荐答案

您无法启动一个对话框,除了通过活动,很抱歉。

You cannot launch a dialog except via an activity, sorry.

欢迎您创建一个使用 Theme.Dialog 或东西看起来有点像一个对话的活动,如果你想。

You are welcome to create an activity that uses Theme.Dialog or something to look a bit like a dialog, if you wish.