# 解决AndroidUnable to addwindow异常
在Android开发中,有时候我们会遇到一个异常:“Unable to addwindow”,这个异常通常发生在尝试向一个已经被销毁的Activity添加一个新的窗口时。这个异常的原因可能是我们在Activity已经销毁的情况下仍然尝试向其添加新的窗口,导致系统无法找到正确的窗口容器来展示新的内容。
## 为什么会发生这个
做一个悬浮窗口,报错:java.lang.RuntimeException: Unable to create service com.spacesoftwares.floatingwindowdemo.MainService: android.view.WindowManager$BadTokenException: Unable to addwindowandroid.view.V...
做一个悬浮窗口,报错:java.lang.RuntimeException: Unable to create service com.spacesoftwares.floatingwindowdemo.MainService: android.view.WindowManager$BadTokenException: Unable to addwindowandroid.view.V...
之前遇到过这样的问题,04-12 10:40:33.302: E/AndroidRuntime(17213): Caused by: android.view.WindowManager$BadTokenException: Unable to addwindow — token null is not for an application 04-12 10:40:33.302: E/Andro