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();

    原文作者:唠嗑008
    原文地址: https://www.jianshu.com/p/cd60bd0c443d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞