09-29 21:44:08.557: ERROR/ActivityThread(31036): Activity XXX has leaked IntentReceiver
Android.widget.ZoomButtonsController$1@419abcf0 that was originally registered here. Are you missing a call to unregisterReceiver()?
09-29 21:44:08.557: ERROR/ActivityThread(31036): android.app.IntentReceiverLeaked: XXX has leaked IntentReceiver
android.widget.ZoomButtonsController$1@419abcf0 that was originally registered here. Are you missing a call to unregisterReceiver()?
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): java.lang.IllegalArgumentException: Receiver not registered:
android.widget.ZoomButtonsController$1@419abcf0
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at android.app.LoadedApk.forgetReceiverDispatcher
(LoadedApk.java:650)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at android.app.ContextImpl.unregisterReceiver
(ContextImpl.java:1091)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at android.content.ContextWrapper.unregisterReceiver
(ContextWrapper.java:354)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at android.widget.ZoomButtonsController.setVisible
(ZoomButtonsController.java:405)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at android.widget.ZoomButtonsController$2.handleMessage
(ZoomButtonsController.java:179)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at android.os.Looper.loop(Looper.java:152)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at android.app.ActivityThread.main(ActivityThread.java:4559)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at java.lang.reflect.Method.invokeNative(Native Method)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at java.lang.reflect.Method.invoke(Method.java:491)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:841)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
09-29 21:44:08.917: ERROR/AndroidRuntime(31036): at dalvik.system.NativeStart.main(Native Method)
WebView中包含一個ZoomButtonsController,當使用web.getSettings().setBuiltInZoomControls(true);啟用後,用戶一旦觸摸屏幕,就會出現縮放控制圖標。這個圖標過上幾秒會自動消失,但在3.X系統上,如果圖標自動消失前退出當前Activity的話,就會報上面的這些異常。
根據異常信息再參考一下WebView的源碼就可以知道ZoomButtonsController有一個register和unregister的過程。但是這兩個過程是我們控制不了的,WebView有顯示控制的API但我們訪問不過。我們能訪問到的只有這幾個和ZoomButtonsController的控制相關:
void setBuiltInZoomControls(boolean enabled)
void setDefaultZoom(WebSettings.ZoomDensity zoom)
void setDisplayZoomControls(boolean enabled)
void setSupportZoom(boolean support)
試過了一遍都不管用。
最後看終極解析方案吧
在Activity的onDestroy裡面加上這麼一句:web.setVisibility(View.GONE);把WebView設置為GONE就可以了。
另外,這個問題在2.X上面不存在。