service中显示一个dialog

dialog是依附于activity存在的。但是app中经常需要使用以下的情况,在service中做一些后台操作,在某个临界条件满足时,显示一个dialog告知用户。
这时dialog无法直接从service中启动起来,会报出android.view.WindowManager$BadTokenException:Unable to add window的错误

参考
service中显示一个dialog
http://blog.csdn.net/huxueyan521/article/details/8954844

原文地址:https://www.cnblogs.com/lijunamneg/p/4468969.html