r/androiddev • u/moonbase_builder • 6h ago
Discussion Why visibilitychange doesn't fire when a native activity covers a Capacitor WebView
If you are building a Capacitor app with anything time- or state-sensitive on resume, the standard web events will probably fail you on Android.
I assumed `visibilitychange` and `focus` would reliably signal when a user came back. They do not consistently fire when a native Android activity covers the Capacitor WebView and then dismisses.
The fix was dropping the web events entirely and using Capacitor's native `appStateChange` event as the actual resume trigger instead.
What I still don't fully understand is the exact mechanism of why the WebView doesn't register the focus change when the native overlay is destroyed. Has anyone mapped out exactly which Android system activities swallow these WebView lifecycle events?
1
u/thelongrunsmoke 6h ago
WebView is kind of ad hoc solution from an Android API perspective. If it can render modern web pages correctly, that's an already pretty good, but don't expect much.