如何根据需要安全地打开和关闭

如何根据需要安全地打开和关闭

本文介绍了如何根据需要安全地打开和关闭 WebView 缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如在这个未回答的问题中提到的:WebView 抛出接收器未注册:android.widget.ZoomButtonsController

As mentioned in this unanswered question: WebView throws Receiver not registered: android.widget.ZoomButtonsController

根据需要打开和关闭 WebView 缩放控件会抛出这个:

By turning the WebView zoom controls on and off as needed throws this:

java.lang.IllegalArgumentException: Receiver not registered: android.widget.ZoomButtonsController

对于某些用户.我自己还没有看到这个崩溃,但我在来自野外设备的日志中看到了它.它不会经常发生,但无论如何它都是崩溃.有什么想法吗?

For some users. I myself have not seen this crash, but I have seen it in the logs coming from devices in the wild. It doesn't happen super frequently, but it is a crash regardless. Any ideas?

谢谢

更新:如何复制

我找到了重现此崩溃的方法:http://code.google.com/p/android/issues/detail?id=15694

I found how to reproduce this crash: http://code.google.com/p/android/issues/detail?id=15694

如果我发现了解决方法,我会回来报告.

I'll report back if I discover a workaround.

根据要求,完整的堆栈跟踪:

java.lang.IllegalArgumentException: Receiver not registered: android.widget.ZoomButtonsController$1@487a4290
at android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.java:793)
at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:913)
at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:331)
at android.widget.ZoomButtonsController.setVisible(ZoomButtonsController.java:404)
at android.widget.ZoomButtonsController$2.handleMessage(ZoomButtonsController.java:178)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)

和另一个类似的:

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:391)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:236)
at android.view.Window$LocalWindowManager.removeView(Window.java:432)
at android.widget.ZoomButtonsController.setVisible(ZoomButtonsController.java:406)
at android.widget.ZoomButtonsController$2.handleMessage(ZoomButtonsController.java:178)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5068)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

推荐答案

在 Zoom 上,我发现如果在调用 WebView.destroy() 之前等待缩放控件淡出,则不会再发生崩溃.所以我已经覆盖了 WebView.destroy() 以在几秒钟后向处理程序发送消息以调用 WebView.destroy() .从 WebView 源我们将看到淡出间隔为:

On a Zoom, I found that if one waits for the zoom control to fade out before calling WebView.destroy() a crash no longer occurs. So I've overwritten WebView.destroy() to post a message to a Handler to call WebView.destroy() after a few seconds. From the WebView source we will see the fade-out interval is:

// The time that the Zoom Controls are visible before fading away
private static final long ZOOM_CONTROLS_TIMEOUT =
        ViewConfiguration.getZoomControlsTimeout();

所以我使用 ViewConfiguration.getZoomControlsTimeout() + 1000L 作为调用 WebView 的 destroy 方法之前的延迟.到目前为止没有崩溃.

So I used ViewConfiguration.getZoomControlsTimeout() + 1000L as the delay before calling WebView's destroy method. So far no crashes.

这篇关于如何根据需要安全地打开和关闭 WebView 缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 07:48