Application attempted to call on a destroyed WebView - cordova (Android)

19,008

I was receiving similar error, but for adView (which is a webview). This helped me to fix my error with "Application attempted to call on a destroyed WebView." Replace adView with the instance of a WebView, should work.

 @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();
}

Other answers from StackOverflow say to make the above three calls on void onDestroy() but I continued to experience same problems. The working solution as seen above, you want to separate the adView.destroy() from removeAllViews() calls.

I also recommend you call adView.resume() and adView.pause() in appropriate places.

Share:
19,008
Elangovan Eaaswaramurty
Author by

Elangovan Eaaswaramurty

3.9 years of experience in Full Stack Development. Hands-on experience in Front end web development (Angular 9+, Typescript, React Native, React, Node JS and mobile app - iOS, Android, Apache Cordova, Ionic 3, Rest API and MongoDB) Experience in Agile and Secure Development methodologies. Worked with Bug Tracking tool JIRA Having good exposure with Apple Approval Distribution Process Having good exposure in source code control tools like SVN and GIT with Jenkins (DevOps) Efficient to work independently or as part of a team and quick learning ability for new technologies Strong defect analysis, debugging and problem-solving skills with an understanding of problem analysis methodologies, techniques, and tools

Updated on June 05, 2022

Comments

  • Elangovan Eaaswaramurty
    Elangovan Eaaswaramurty almost 2 years

    when i change the font-size in mobile settings (settings->Display->Font size) My cordova applications redirects to index page(Means Root page), and i am getting

    Application attempted to call on a destroyed WebView

    My Log:

    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)

    Another Log:

    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)

    Can anyone help me through this.