Launch AlertDialog not from an Activity

僤鯓⒐⒋嵵緔 提交于 2020-01-14 04:14:13

问题


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: Unable to add window -- token null is not for an application

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


回答1:


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

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



来源:https://stackoverflow.com/questions/4977002/launch-alertdialog-not-from-an-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!