Android Dialog显示错误 Unable to add window token null is not for an application

弹出一个自定义Dialog,出现如下错误

08-07 21:26:43.506: ERROR/AndroidRuntime(9390): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
LoadingDialog dialog = new LoadingDialog(context); 

其中context为Fragment中

context = getApplicationContext();  

异常原因:Dialog创建语句中,不能使用getApplicationContext()得到的context,而必须使用Activity的context,如果在fragment中,就是context=getActivity();

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容