Dialog 出现的android.view.WindowManager$BadTokenException: Unable to add window异常

Dialog异常:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

异常原因:
new AlertDialog.Builder(Context context)中的参数不能用getApplicationContext()获得的context,而必须使用Activity,因为只有一个Activity才能添加一个窗体。

解决办法:
例如 new AlertDialog.Builder(XXXActivity.this)

猜你喜欢

转载自mfan.iteye.com/blog/1675485