Skip to content

Conversation

@har0ke
Copy link

@har0ke har0ke commented Nov 18, 2025

When switching between dark and light themes in my Capacitor app, it crashed, because onEnd seems to be called when the activity is being recreated:

2025-11-18 22:48:33.840 31976-31976 Capacitor/...oardPlugin my.app                               V  Notifying listeners for event keyboardWillHide
2025-11-18 22:48:33.840 31976-31976 Capacitor/...oardPlugin my.app                               D  No listeners found for event keyboardWillHide
2025-11-18 22:48:34.125 31976-31976 Capacitor/AppPlugin     my.app                               V  Notifying listeners for event pause
2025-11-18 22:48:34.125 31976-31976 Capacitor/AppPlugin     my.app                               D  No listeners found for event pause
2025-11-18 22:48:34.138 31976-31976 Capacitor               my.app                               D  App paused
2025-11-18 22:48:34.140 31976-31976 Capacitor/AppPlugin     my.app                               D  Firing change: false
2025-11-18 22:48:34.140 31976-31976 Capacitor/AppPlugin     my.app                               V  Notifying listeners for event appStateChange
2025-11-18 22:48:34.140 31976-31976 Capacitor/AppPlugin     my.app                               D  No listeners found for event appStateChange
2025-11-18 22:48:34.140 31976-31976 Capacitor               my.app                               D  App stopped
2025-11-18 22:48:34.141 31976-31976 Capacitor               my.app                               D  Saving instance state!
2025-11-18 22:48:34.147 31976-31976 Capacitor               my.app                               D  App destroyed
2025-11-18 22:48:34.148  1833-5650  CoreBackPreview         system_server                        D  Window{d2de435 u0 my.app                /my.app                .MainActivity}: Setting back callback null
2025-11-18 22:48:34.156 31976-31976 AndroidRuntime          my.app                               D  Shutting down VM
2025-11-18 22:48:34.159 31976-31976 AndroidRuntime          my.app                               E  FATAL EXCEPTION: main
                                                                                                    Process: my.app                , PID: 31976
                                                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean androidx.core.view.WindowInsetsCompat.isVisible(int)' on a null object reference
                                                                                                    	at com.capacitorjs.plugins.keyboard.Keyboard$1.onEnd(Keyboard.java:99)
                                                                                                    	at androidx.core.view.WindowInsetsAnimationCompat$Impl30$ProxyCallback.onEnd(WindowInsetsAnimationCompat.java:1079)
                                                                                                    	at android.view.View.dispatchWindowInsetsAnimationEnd(View.java:11753)
                                                                                                    	at android.view.ViewGroup.dispatchWindowInsetsAnimationEnd(ViewGroup.java:7470)
                                                                                                    	at android.view.ViewRootInsetsControllerHost.dispatchWindowInsetsAnimationEnd(ViewRootInsetsControllerHost.java:117)
                                                                                                    	at android.view.InsetsController.dispatchAnimationEnd(InsetsController.java:1587)
                                                                                                    	at android.view.InsetsController.cancelAnimation(InsetsController.java:1356)
                                                                                                    	at android.view.InsetsController.cancelExistingControllers(InsetsController.java:1278)
                                                                                                    	at android.view.InsetsController.cancelExistingAnimations(InsetsController.java:1536)
                                                                                                    	at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:5394)
                                                                                                    	at android.view.ViewRootImpl.doDie(ViewRootImpl.java:8815)
                                                                                                    	at android.view.ViewRootImpl.die(ViewRootImpl.java:8791)
                                                                                                    	at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:506)
                                                                                                    	at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:447)
                                                                                                    	at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:206)
                                                                                                    	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5483)
                                                                                                    	at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5759)
                                                                                                    	at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5674)
                                                                                                    	at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:71)
                                                                                                    	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                    	at android.os.Looper.loop(Looper.java:288)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:7924)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

This PR has two commits that both fix the issue individually, one by unregistering the handler on destroy and the other handling null values if the view is detached.

Not sure if we need both, feedback is appreciated @alexgerardojacinto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant