【问题标题】:Application attempted to call on a destroyed WebView - cordova (Android)应用程序试图调用被破坏的 WebView - cordova (Android)
【发布时间】:2018-04-27 10:02:23
【问题描述】:

当我在移动设置中更改字体大小时(settings->Display->Font size) 我的科尔多瓦应用程序重定向到索引页面(意味着根页面), 我得到了

应用程序试图调用已销毁的WebView

我的日志:

Application attempted to call on a destroyed WebView java.lang.Throwable at org.chromium.android_webview.AwContents.isDestroyed(AwContents.java:349) at org.chromium.android_webview.AwContents.isDestroyedOrNoOperation(AwContents.jav :321) org.chromium.android_webview.AwContents.getTitle(AwContents.java:576) at org.chromium.android_webview.AwWebContentsDelegateAdapter.loadingStateChanged(AwWebContentsDelegateAdapter.java:132) at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:9)at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5451) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

另一个日志:

E/ActivityThread: Activity MainActivity has leaked IntentReceiver org.apache.cordova.engine.SystemWebViewEngine$2@5c35c47 that was originally registered here. Are you missing a call to unregisterReceiver()? android.app.IntentReceiverLeaked: Activity .MainActivity has leaked IntentReceiver org.apache.cordova.engine.SystemWebViewEngine$2@5c35c47 that was originally registered here. Are you missing a call to unregisterReceiver()? at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:921) at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:722) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1193) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1173) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1167) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:561) at org.apache.cordova.engine.SystemWebViewEngine.initWebViewSettings(SystemWebViewEngine.java:242) at org.apache.cordova.engine.SystemWebViewEngine.init(SystemWebViewEngine.java:108) at org.apache.cordova.CordovaWebViewImpl.init(CordovaWebViewImpl.java:110) at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:149) at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:224) at .MainActivity.adjustFontScale(MainActivity.java:68) at .MainActivity.onCreate(MainActivity.java:47) at android.app.Activity.performCreate(Activity.java:6323) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) at android.app.ActivityThread.access$900(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5451) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 04-27 15:44:30.643 3522-3522/ E/ActivityThread: Activity .MainActivity has leaked IntentReceiver org.apache.cordova.CoreAndroid$5@ea2742b that was originally registered here. Are you missing a call to unregisterReceiver()? android.app.IntentReceiverLeaked: Activity .MainActivity has leaked IntentReceiver org.apache.cordova.CoreAndroid$5@ea2742b that was originally registered here. Are you missing a call to unregisterReceiver()? at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:921) at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:722) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1193) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1173) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1167) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:561) at org.apache.cordova.CoreAndroid.initTelephonyReceiver(CoreAndroid.java:314) at org.apache.cordova.CoreAndroid.pluginInitialize(CoreAndroid.java:63) at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:58) at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171) at org.apache.cordova.PluginManager.exec(PluginManager.java:122) at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57) at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:9) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.os.HandlerThread.run(HandlerThread.java:61) 04-27 15:44:30.644 3522-3522/ E/ActivityThread: Activity .MainActivity has leaked IntentReceiver org.apache.cordova.networkinformation.NetworkManager$1@ee337ef that was originally registered here. Are you missing a call to unregisterReceiver()? android.app.IntentReceiverLeaked: Activity .MainActivity has leaked IntentReceiver org.apache.cordova.networkinformation.NetworkManager$1@ee337ef that was originally registered here. Are you missing a call to unregisterReceiver()? at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:921) at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:722) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1193) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1173) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1167) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:561) at org.apache.cordova.networkinformation.NetworkManager.initialize(NetworkManager.java:114) at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:57) at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171) at org.apache.cordova.PluginManager.exec(PluginManager.java:122) at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57) at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:9) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.os.HandlerThread.run(HandlerThread.java:61)

谁能帮我解决这个问题。

【问题讨论】:

    标签: javascript android jquery cordova


    【解决方案1】:

    我收到了类似的错误,但对于 adView(这是一个 webview)。这帮助我解决了“应用程序试图调用已损坏的 WebView”的错误。将 adView 替换为 WebView 的实例,应该可以工作。

     @Override
    public void onDestroyView() {
        if(adView != null) {
             //rootView is the inflated view of the fragment/activity
            ((ViewGroup) rootView.getParent()).removeAllViews();
            adView.removeAllViews();
            super.onDestroyView();
        }
    }
    
    @Override
    public void onDestroy() {
        if(adView != null) adView.destroy();
        super.onDestroy();
    }
    

    StackOverflow 的其他答案说要对 void onDestroy() 进行上述三个调用,但我仍然遇到同样的问题。工作解决方案 如上所示,您希望将 adView.destroy()removeAllViews() 调用分开。

    我还建议您在适当的地方致电adView.resume()adView.pause()

    【讨论】:

      猜你喜欢
      • 2016-06-28
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      • 2016-11-10
      相关资源
      最近更新 更多