Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android WebView canGoBack始终返回false_Java_Android_Google Chrome_Webview - Fatal编程技术网

Java Android WebView canGoBack始终返回false

Java Android WebView canGoBack始终返回false,java,android,google-chrome,webview,Java,Android,Google Chrome,Webview,重现问题的步骤: 创建一个包含WebView的片段 在WebView中深入浏览几个站点,构建历史记录 尝试使用webview.canGoBack()函数 注意,它总是返回false 这是一种新的行为,因为WebView以前确实返回true 新版本的WebView似乎破坏了这一功能 这是我的密码: class MyWebViewClient extends WebViewClient { // Loads all hyperlinks in the existing WebView

重现问题的步骤:

  • 创建一个包含WebView的片段

  • 在WebView中深入浏览几个站点,构建历史记录

  • 尝试使用webview.canGoBack()函数

  • 注意,它总是返回false

  • 这是一种新的行为,因为WebView以前确实返回true

    新版本的WebView似乎破坏了这一功能

    这是我的密码:

    class MyWebViewClient extends WebViewClient {
            // Loads all hyperlinks in the existing WebView
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // Protection against getActivity() returning null object reference
                if (!isAdded()) return true;
    
                // Allow WebView to load url
                Uri uri = Uri.parse(url);
                // Google Maps
                if (url.contains("maps.google")) {
                    Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
                    mapIntent.setPackage("com.google.android.apps.maps");
                    if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                        startActivity(mapIntent);
                    }
                    return true;
                }
                // Telephone
                else if (url.contains("tel:")) {
                    String phoneNumber = url.substring(4);
                    Utils.dialPhone(getActivity(), phoneNumber);
    
                    return true;
                }
    
                // Redirect
                return false;
            }
    }
    
    下面是我使用goBack API的地方:

    public boolean canWebViewGoBack() {
        if (mWebView != null) {
            if (mWebView.canGoBack()) {
                return true;
            }
        }
    
        return false;
    }
    
    public void webViewGoBack() {
        if (mWebView != null) {
            if (mWebView.canGoBack()) {
                mWebView.goBack();
            }
        }
    }
    
    这里


    讨论问题和可能的解决方案

    最新Chrome发布后,WebView canGoBack功能再次发挥作用:


    64.0.3282.137

    或者它是一个网站……是的,你说得对,因为新版本的WebView似乎破坏了这一功能。这里也一样。这个链接中唯一的解决方案是等到下一个Chrome版本(65)。