0

I have created a custom keyboard, whenever it switches from potrait to lanscape it gives the following error and crashes:

2020-07-04 16:31:38.846 24634-24634/com.nisarg.nboard E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.nisarg.nboard, PID: 24634
    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
        at android.view.ViewGroup.addViewInner(ViewGroup.java:4939)
        at android.view.ViewGroup.addView(ViewGroup.java:4770)
        at android.view.ViewGroup.addView(ViewGroup.java:4742)
        at android.inputmethodservice.InputMethodService.setInputView(InputMethodService.java:1483)
        at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1325)
        at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:1767)
        at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:1735)
        at android.inputmethodservice.InputMethodService.resetStateForNewConfiguration(InputMethodService.java:1003)
        at android.inputmethodservice.InputMethodService.onConfigurationChanged(InputMethodService.java:984)
        at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:4918)
        at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:5108)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1731)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:6635)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

I don't know why I am getting this error, could please someone help me out.

1 Answers1

0

I found it, i was inflating views in onCreate() of the InputMethodService, which is not called after a configuration change in this case, so the views which were to be about to set to a new dialoug(every keyboard is a special kind of dialog box) they would be attatched to the previous parent box(supposedly setInputView() method does this) hence, i copied the code there and added it to onInitializeInterface(), it is called both after creating the service and after configuration change, so i would generate new views every configuration change so that they are not attatched to any root.