Android Webview Destroy

Asked

Viewed 177 times

-1

Opa personal I am with a certain problem when I run a Destroy in a webview.

    wb.getSettings().setAllowFileAccess(true);
    wb.getSettings().setJavaScriptEnabled(true);
    wb.getSettings().setRenderPriority(RenderPriority.HIGH);
    wb.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

detail this only occurs when i Seto the Javascriptenable.

            mWebContainer.removeView(wb);
            wb.clearHistory();
            wb.stopLoading();
            wb.clearView();
            wb.clearCache(true);
            wb.destroyDrawingCache();
            wb.setWebChromeClient(null);
            wb.setWebViewClient(null);
            wb.getSettings().setJavaScriptEnabled(false);
            wb.removeAllViews();
            wb.destroy(); 

I’ve tried almost everything to give Stroy without the mistake happening

04-02 13:34:14.893: E/webview(24263): java.lang.Throwable: Error: Webview.Destroy() called while still Attached! 04-02 13:34:14.893: E/webview(24263): at android.webkit.Webviewclassic.Destroy(Webviewclassic.java:2188) 04-02 13:34:14.893: E/webview(24263): at android.webkit.Webview.Destroy(Webview.java:647) 04-02 13:34:14.893: E/webview(24263): at android.view.View.performClick(View.java:4421) 04-02 13:34:14.893: E/webview(24263): at android.view.View$Performclick.run(View.java:17903) 04-02 13:34:14.893: E/webview(24263): at android.os.Handler.handleCallback(Handler.java:730) 04-02 13:34:14.893: E/webview(24263): at android.os.Handler.dispatchMessage(Handler.java:92) 04-02 13:34:14.893: E/webview(24263): at android.os.Looper.loop(Looper.java:213) 04-02 13:34:14.893: E/webview(24263): at android.app.Activitythread.main(Activitythread.java:5225) 04-02 13:34:14.893: E/webview(24263): at java.lang.reflect.Method.invokeNative(Native Method) 04-02 13:34:14.893: E/webview(24263): at java.lang.reflect.Method.invoke(Method.java:525) 04-02 13:34:14.893: E/webview(24263): at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:741) 04-02 13:34:14.893: E/webview(24263): at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:557) 04-02 13:34:14.893: E/webview(24263): at Dalvik.system.Nativestart.main(Native Method) 04-02 13:34:15.294: E/androidruntime(24263): FATAL EXCEPTION: main 04-02 13:34:15.294: E/androidruntime(24263): java.lang.Nullpointerexception 04-02 13:34:15.294: E/androidruntime(24263): at android.webkit.Zoommanager.onSizeChanged(Zoommanager.java:955) 04-02 13:34:15.294: E/androidruntime(24263): at android.webkit.Webviewclassic.onSizeChanged(Webviewclassic.java:5689) 04-02 13:34:15.294: E/androidruntime(24263): at android.webkit.Webview.onSizeChanged(Webview.java:2157) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.View.sizeChange(View.java:14582) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.View.setFrame(View.java:14557) 04-02 13:34:15.294: E/androidruntime(24263): at android.webkit.Webview.access$701(Webview.java:243) 04-02 13:34:15.294: E/androidruntime(24263): at android.webkit.Webview$Privateaccess.super_setFrame(Webview.java:1788) 04-02 13:34:15.294: E/Androidruntime(24263): at android.webkit.Webviewclassic.setFrame(Webviewclassic.java:5665) 04-02 13:34:15.294: E/androidruntime(24263): at android.webkit.Webview.setFrame(Webview.java:2151) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.View.layout(View.java:14468) 04-02 13:34:15.294: E/Androidruntime(24263): at android.view.Viewgroup.layout(Viewgroup.java:4562) 04-02 13:34:15.294: E/androidruntime(24263): at android.widget.Relativelayout.onLayout(Relativelayout.java:1076) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.View.layout(View.java:14471) 04-02 13:34:15.294: E/Androidruntime(24263): at android.view.Viewgroup.layout(Viewgroup.java:4562) 04-02 13:34:15.294: E/androidruntime(24263): at android.widget.Framelayout.onLayout(Framelayout.java:452) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.View.layout(View.java:14471) 04-02 13:34:15.294: E/Androidruntime(24263): at android.view.Viewgroup.layout(Viewgroup.java:4562) 04-02 13:34:15.294: E/androidruntime(24263): at android.widget.Linearlayout.setChildFrame(Linearlayout.java:1671) 04-02 13:34:15.294: E/androidruntime(24263): at android.widget.Linearlayout.layoutVertical(Linearlayout.java:1525) 04-02 13:34:15.294: E/androidruntime(24263): at android.widget.Linearlayout.onLayout(Linearlayout.java:1434) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.View.layout(View.java:14471) 04-02 13:34:15.294: E/Androidruntime(24263): at android.view.Viewgroup.layout(Viewgroup.java:4562) 04-02 13:34:15.294: E/androidruntime(24263): at android.widget.Framelayout.onLayout(Framelayout.java:452) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.View.layout(View.java:14471) 04-02 13:34:15.294: E/Androidruntime(24263): at android.view.Viewgroup.layout(Viewgroup.java:4562) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.Viewrootimpl.performLayout(Viewrootimpl.java:1984) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.Viewrootimpl.performTraversals(Viewrootimpl.java:1738) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.Viewrootimpl.doTraversal(Viewrootimpl.java:1008) 04-02 13:34:15.294: E/Androidruntime(24263): at android.view.Viewrootimpl$Traversalrunnable.run(Viewrootimpl.java:5508) 04-02 13:34:15.294: E/Androidruntime(24263): at android.view.Choreographer$Callbackrecord.run(Choreographer.java:749) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.Choreographer.doCallbacks(Choreographer.java:562) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.Choreographer.doFrame(Choreographer.java:532) 04-02 13:34:15.294: E/androidruntime(24263): at android.view.Choreographer$Framedisplayeventreceiver.run(Choreographer.java:735) 04-02 13:34:15.294: E/androidruntime(24263): at android.os.Handler.handleCallback(Handler.java:730) 04-02 13:34:15.294: E/androidruntime(24263): at android.os.Handler.dispatchMessage(Handler.java:92) 04-02 13:34:15.294: E/androidruntime(24263): at android.os.Looper.loop(Looper.java:213) 04-02 13:34:15.294: E/androidruntime(24263): at android.app.Activitythread.main(Activitythread.java:5225) 04-02 13:34:15.294: E/Androidruntime(24263): at java.lang.reflect.Method.invokeNative(Native Method) 04-02 13:34:15.294: E/Androidruntime(24263): at java.lang.reflect.Method.invoke(Method.java:525) 04-02 13:34:15.294: E/Androidruntime(24263): at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:741) 04-02 13:34:15.294: E/Androidruntime(24263): at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:557) 04-02 13:34:15.294: E/androidruntime(24263): at Dalvik.system.Nativestart.main(Native Method)

1 answer

1


You need to remove Webview from your view. Example:

webViewPlaceholder.removeView(myWebView);
myWebView.removeAllViews();
myWebView.destroy();

ONLY in English


Here is a simple example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" android:id="@+id/root" >

    <WebView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/webView" android:layout_gravity="center_horizontal"/>

    <Button android:layout_width="fill_parent" android:text="Remove" android:layout_height="wrap_content" android:onClick="onClickButton"/>
</LinearLayout>
public class MyActivity extends Activity {
    private WebView wb;
    private LinearLayout ll;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.wb = (WebView) findViewById(R.id.webView);
        this.wb.getSettings().setJavaScriptEnabled(true);
        this.wb.getSettings().setAllowFileAccess(true);
        this.wb.getSettings().setJavaScriptEnabled(true);
        this.wb.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
        this.wb.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

        this.ll = (LinearLayout)findViewById(R.id.root);
    }

    @Override
    protected void onResume() {
        super.onResume();
        this.wb.loadUrl("http://www.google.com");
    }

    public void onClickButton(View view) {
        //deatach the view
        ll.removeView(wb);
        wb.clearHistory();
        wb.stopLoading();
        wb.clearView();
        wb.clearCache(true);
        wb.destroyDrawingCache();
        wb.setWebChromeClient(null);
        wb.setWebViewClient(null);
        wb.getSettings().setJavaScriptEnabled(false);
        wb.removeAllViews();
        wb.destroy();
    }
}
  • Well I’ve tried removing it from the view, but the same error persists.

  • Tried to disable javascript before removing webview?

  • Yes, Wb.getSettings(). setJavaScriptEnabled(false); although it is not very recommended to do this I did and the error persists.

  • Where do you call Wb.Destroy()? Within which method?

  • Inside a click on a button

  • Which version of Android are you using? You can post xml and class?

  • Poxa Otto do not know why but my webView was inside a linear that was inside a relative so I took the linear I left only the relative and it worked but his example helped a lot VLWZÂO !!!

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.