Android-AdvancedWebView
Android-AdvancedWebView copied to clipboard
Why does the WebView call resumeTimers/pauseTimers ?
Hey, Hey why do you call resumeTimers /pauseTimers in onResume/onPause ? These functions affect all WebViews in the app.
You can see In onPause comment. https://android.googlesource.com/platform/frameworks/base/+/a5408e6/core/java/android/webkit/WebView.java#1140
That calling webView.onPause should be enough.
This affects all webViews that don't call these functions.
Thanks
Thanks for your question!
Let’s just see what the official documentation says about this:
-
onPause:[…] Note that this call does not pause JavaScript. To pause JavaScript globally, use
pauseTimers(). […] -
pauseTimers:[…] This can be useful if the application has been paused.
So that’s why it had been implemented.
In addition, onPause had not been available initially, though it has now been available for quite some time.
Most use cases have a single WebView (at a time), where this solution works perfectly.
If we want to remove the calls, we should do a thorough investigation regarding its effects. Alternatively, we could allow for these calls to be disabled (while still enabling them by default).
Thanks for the fast response. My issue with this is that you change a global state with a specific instance.
I'n my case i have a fragment with AdvancedWebView that can open a new Fragment with the native WebView.
So the Native WebView stops working in this scenario.
As you added from the official documentation - This can be useful if the application has been paused.
I would call pauseTimers() only in this scenario.
not when the fragment is paused.
I think the removal of these functions should be investigated but for now i think a disable function is a good idea.
Thanks again