簡體   English   中英

Android webview 崩潰“致命信號 5 (SIGTRAP)”

[英]Android webview crash "Fatal signal 5 (SIGTRAP)"

我有一個帶有 web 視圖的應用程序,我在其中加載了 HTML 內容並啟用了 JavaScript。 web 視圖位於片段內。

這就是我在片段的onCreateView方法中初始化 web 視圖的方式:

WebView webview = (WebView) mainView.findViewById(R.id.webview);

WebSettings webSettings = webview.getSettings();

webSettings.setJavaScriptEnabled(true);
webSettings.setDisplayZoomControls(false);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);

webview.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        /*
        * My code
        */
    }
});

webview.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
        WebView.HitTestResult result = view.getHitTestResult();
        String data = result.getExtra();
        if (data != null) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
            startActivity(browserIntent);
        }
        return false;
    }
});

webview.loadDataWithBaseURL(baseUrl, htmlData, "text/html", "utf-8", "");

在web視圖中,一個map加載了JavaScript。在這個map上,我們可以點擊元素,加載照片。 單擊時,照片將顯示在彈出窗口中(仍在 web 視圖內)。 當我單擊后退按鈕將 go 返回到 map 時,應用程序崩潰了。

應用程序崩潰的 GIF

這是錯誤日志:

A/libc:致命信號 5 (SIGTRAP),tid 949 中的代碼 1 (Chrome_InProcRe) [ 03-21 11:26:08.510 364: 364 W/ ] debuggerd: 處理請求:pid=32610 uid=10289 gid=10289 tid= 949

我在 Android 7.1.1、6.0.1、5.0.2 上測試並崩潰。 然后我嘗試使用 Android 4.4.2,應用程序沒有崩潰。

當我點擊后退按鈕時(正如我們在 GIF 上看到的那樣),它應該 go 返回到之前的 state 並關閉彈出窗口

這應該在 Activity.java 的 onCreate 方法之前

    webView.setWebViewClient(new MyBrowser());

嘗試覆蓋后退導航功能並自己關閉彈出窗口。

您不需要處理所有堆棧導航邏輯,只需在顯示此彈出窗口時有一個狀態即可。 應用您自己的導航邏輯(例如手動關閉彈出窗口)。

void onBackPressed(){
    if(isTheBuggyPopupIsOn){
        closeTheBuggyPopup();
    }
    else{
        super.onBackPressed();
    }
}
    webView.setWebViewClient(new MyBrowser());


public class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub

            if (url.equals(""YOUR URL)) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            } else {
                return false;
            }

        }

    }

嘗試這個....

首先添加這個

webView.setWebViewClient(new MyBrowser());

然后添加這個

public class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub

            if (url.equals(""YOUR URL)) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            } else {
                return false;
            }

        }

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM