[ERROR]android.view.WindowManager$BadTokenException: Unable to add window — token null
2016-08-16 15:00
483 查看
在实践中才能更快的学习编程,书上的东西永远都是不够的
很明显这里是需要传一个context过去的,那么应该选哪一个呢?
答案是:CurrentActivity,这个指的是当前所处的Activity。
这里涉及到一个生命周期的问题,getApplicationContext() 取的是这个应用程序的Context,Activity.this取的是这个Activity的Context,这两者的生命周期是不同的,前者的生命周期是整个应用,后者的生命周期只是它所在的Activity.
这两者的区别造成了标题上的错误,同时自定义的对话框也不能显示出来
相关文章:
http://blog.csdn.net/jason0539/article/details/9658519
_Dialog _dialog = new _Dialog(...); //getApplicationContext() //CurrentActivity.this _dialog.show();
很明显这里是需要传一个context过去的,那么应该选哪一个呢?
答案是:CurrentActivity,这个指的是当前所处的Activity。
这里涉及到一个生命周期的问题,getApplicationContext() 取的是这个应用程序的Context,Activity.this取的是这个Activity的Context,这两者的生命周期是不同的,前者的生命周期是整个应用,后者的生命周期只是它所在的Activity.
这两者的区别造成了标题上的错误,同时自定义的对话框也不能显示出来
相关文章:
http://blog.csdn.net/jason0539/article/details/9658519
相关文章推荐
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- 异常 android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- 试用dialog时碰到android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- 关于android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an app
- android.view.WindowManager$BadTokenException: Unable to add window -- token
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli