Android 4.4系统在onReceivedError给ERR_CACHE_MISS错误回来的WebView [英] Android 4.4 giving ERR_CACHE_MISS error in onReceivedError for WebView back

查看:2102
本文介绍了Android 4.4系统在onReceivedError给ERR_CACHE_MISS错误回来的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的布局一个web视图。默认情况下,搜索的形式在它打开。在搜索中,上市部分将出现下面的搜索形式。如果列表中的任何链接被点击,详细信息页面打开。现在我想控制的后退导航的web视图。我放在这个活动code。

I have a webview in my Layout. By default, a search form is opened in it. On search, a listing section appears below the search form. If any link in the list is clicked, the details page opened. Now I want to controlled the back navigation for the webview. I placed this code in Activity.

    @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {

            Log.d("TYPE", TYPE);

            WebView myWebView = null;
            if (TYPE.equalsIgnoreCase("REPORT_ACTIVITY"))
                myWebView = reportView;

            if (TYPE.equalsIgnoreCase("FEEDBACK_ACTIVITY"))
                myWebView = feedbackView;

            if (myWebView != null)
                // Check if the key event was the Back button and if there's history
                if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
                    myWebView.goBack();
                    return true;
                }
            // If it wasn't the Back key or there's no web page history, bubble up
            // to the default
            // system behavior (probably exit the activity)
            return super.onKeyDown(keyCode, event);
        }

private WebViewClient webViewClient = new WebViewClient() {
  public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.d("onPageStarted", "onPageStarted");
            loadProgressBarBox.setVisibility(View.VISIBLE);
            //view.setVisibility(View.GONE);
        }

        public void onPageFinished(WebView view, String url) {
            Log.d("onPageFinished", "onPageFinished");
            loadProgressBarBox.setVisibility(View.GONE);
        }

        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {

            Log.d("Error", "Error code: " + errorCode + "/" + description);
       }

}

我还设定了的WebView一个WebViewClient。当我回去使用后退按钮它工作正常任何版本4.4。但是,当我试图在Android 4.4系统,它回来了,从精细详情页列表页。但是当我试图再回去,它的投掷的错误code -1和ERR_CACHE_MISS的描述。不显示任何页面。

I have also set a WebViewClient with the WebView. When I going back using back button it is working fine for any version 4.4. But when I am trying in Android 4.4, it is coming back fine from details page to listing page. But as soon as I am trying to go back again, its throwing error code -1 and ERR_CACHE_MISS in description. No page is displayed.

09-04 06:59:05.666: D/Error(1102): Error code: -1/net::ERR_CACHE_MISS

如何解决这个问题,Android 4.4系统?

How to solve this problem in Android 4.4?

推荐答案

此错误实际上是从您的应用程序之外梗在大多数情况下(有时它只是一个缺少网​​络许可,但这并不听起来像这里的情况)。

This error actually stems from outside of your application in most cases (occasionally it's just a missing INTERNET permission, but that doesn't sound like the case here).

我打字了解释,但发现一个更简单的例子,这个答案双打作为解释的另一个问题。以下是有关的位,再散列一点:

I was typing out an explanation, but found a much more straightforward example that doubles as an explanation in this answer to another question. Here's the relevant bits, re-hashed a little:

  1. 乔填写订单的形式与他的信用卡信息
  2. 的信息,并返回标有1 在头无缓存确认/收据页面,这意味着它总是会从服务器请求的服务器进程。
  3. 乔转到另一个页面。
  4. 在乔点击回来了,因为他要仔细检查一下,把他的确认页面。
  1. Joe fills in an order form with his credit card information
  2. The server processes that information and returns a confirmation/receipt page that's marked with no-cache in the header, meaning it will always be requested from the server.
  3. Joe goes to another page.
  4. Joe clicks back because he wants to double check something, taking him to the confirmation page.

该问题是由这最后一步。确认页面标记用无缓存,因此它必须从服务器再次请求。但正确地显示相同的页,需要使通第一次相同的数据获得再次发送。

The problem arises from that last step. The confirmation page was marked with no-cache, so it has to be requested from the server again. But to show the same page correctly, the same data that was passed the first time needs to get sent again.

这导致了乔越来越结算了两次,因为一个新的请求正在取得相同的信息为最后一次。乔将不会是一个快乐的人,当他发现他的账户两项指控和一对额外的帐篷在他家门口。

This results in Joe getting billed twice, since a new request is being made with the same information as last time. Joe will not be a happy camper when he finds two charges on his account and an extra pair of tents on his doorstep.

看来这种情况是相当普及了,它现在在大多数浏览器的标准误差,显然,新版本的Andr​​oid。错误实际上是从铬起源,这就是为什么你会看到在谷歌Chrome浏览器相同的错误,为什么你只看到它在4.4(其中引进的WebView的基于铬)。

It seems this situation was common enough that it is now a standard error across most browsers, and apparently, newer versions of Android. The error actually originates from Chromium, which is why you'll see the same error in Google Chrome, and why you only see it in 4.4 (which introduced a new version of the WebView based on Chromium).

事实上,你实际上可能看到它之前,它显示了在大多数浏览器警告你沿着要刷新此页面东西线的消息,浏览器将不得不重新发送数据...亚达内容十分重要

In fact, you have actually probably seen it before, it's the message that shows up in most browsers warning you with something along the lines of "To refresh this page, the browser will have to resend data...yada yada yada".

这是Android 4.4系统的方式警告是怎么回事你。如何解决这真的取决于你要连接什么,但是如果搜索这种情况下,你会发现它的相当普遍,并具有修复。错误的确切触发实际上是当请求不能从缓存提供服务(在这种情况下,无缓存引起的)。

This is Android 4.4's way warning you of what's going on. How to fix it really depends on what you're connecting to, but if you search for this situation, you'll find that it's fairly common, and has fixes. The exact trigger of the error is actually when the request can't be serviced from cache (in this case, no-cache is causing that).

根据请求的性质,也许无缓存是不是真的需要。

Depending on the nature of the request, maybe no-cache isn't actually needed.

不过,从应用程序的角度来看,主要的问题是, onReceiveError 是一种不得已而为之的web视图中。错误你有从底层系统传播。一旦你在那里结束,您将无法继续页面加载的,因为它代表的。所以,你没有机会允许重发,你能不能给这个选项,不同的是,说谷歌浏览器的用户。

But from your application's perspective, the main problem is, onReceiveError is a sort of "last resort" for the WebView. Errors you get there have propagated from underlying system. And once you end up there, you can't continue the page load as it stands. So you don't have a chance to allow that resend, and you can't give the user that option, unlike, say Google Chrome does.

这篇关于Android 4.4系统在onReceivedError给ERR_CACHE_MISS错误回来的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆