I have a EditText inside a PopupWindow, that is displayed correctly, when touched the SoftInput keyboard is open, if a misspelled word is wrote in the field, it will have red underline on it, if it is touched the following Exception occurs.
06-12 16:05:46.136: E/AndroidRuntime(10375): android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@41d51058 is not valid; is your activity running?
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.view.ViewRootImpl.setView(ViewRootImpl.java:769)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:278)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.widget.PopupWindow.invokePopup(PopupWindow.java:1067)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:891)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:855)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.widget.Editor$PinnedPopupWindow.updatePosition(Editor.java:2722)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.widget.Editor$PinnedPopupWindow.show(Editor.java:2670)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.widget.Editor$SuggestionsPopupWindow.show(Editor.java:2921)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.widget.Editor.showSuggestions(Editor.java:2063)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.widget.Editor$1.run(Editor.java:1896)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.os.Handler.handleCallback(Handler.java:733)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.os.Handler.dispatchMessage(Handler.java:95)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.os.Looper.loop(Looper.java:136)
06-12 16:05:46.136: E/AndroidRuntime(10375): at android.app.ActivityThread.main(ActivityThread.java:5479)
06-12 16:05:46.136: E/AndroidRuntime(10375): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 16:05:46.136: E/AndroidRuntime(10375): at java.lang.reflect.Method.invoke(Method.java:515)
06-12 16:05:46.136: E/AndroidRuntime(10375): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
06-12 16:05:46.136: E/AndroidRuntime(10375): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
06-12 16:05:46.136: E/AndroidRuntime(10375): at dalvik.system.NativeStart.main(Native Method)
I found on StackOverflow that an PopupWindow cant be the parent of other, but I have no way to control the keyboard software to use a valid context.
How can I avoid this error?
PS: Happens on Android 4.4.2+ where the keyboard have auto-spell-checking