GoBack的()中的WebView追溯到几乎是一路 [英] goBack() in WebView goes back ALMOST all the way

查看:193
本文介绍了GoBack的()中的WebView追溯到几乎是一路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(编辑:。也许我应该改一下标题,但它仍然正确描述的行为有时当你GoBack的()来加载,有时它甚至不,如果我使用loadURL做第一个URL()在onResume!见code我追加到在这个问题底部的活动。)

( Maybe I should rephrase the title, but it still describes the behavior correctly. Sometimes when you goBack() to the first URL it loads, and sometimes it doesn't. Even if I do it with loadURL() in onResume! See the code I appended to the Activity at the bottom of the question.)

后退按钮覆盖运作良好,并通过我访问过的页面返回。直到它应该回到它加载罚款从的onCreate开始URL。然后,我得到一个小的延迟和一个空白页面,而不是起始页我以前看到的。

The back button override works well and goes back through the pages I've visited. Until it should go back to the start URL which loads fine from onCreate. Then I get a small delay and a blank page, instead of the start page I saw before.

有一些窍门呢?在垃圾邮件的onCreate用相同的URL一些历史阵列不止一次?

Is there some trick to it? Spamming some history array with the same URL more than once in onCreate?

在code被写入与本网站的答案。这是整个Java文件。

The code is written with answers from this site. This is the entire java file.

package se.avia.tdca;

import se.avia.tdca.R;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import android.view.KeyEvent;

public class Inspiration extends Activity {
    Sharedprefs share;
    WebView mywebview;

    @Override
    public void onBackPressed(){    //for < 4

        if (mywebview.canGoBack()) {
            mywebview.goBack();
            mywebview.reload(); //desperate try
            return;
        }
        super.onBackPressed();      
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mywebview.canGoBack()) {
            mywebview.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.inspiration);

        share=new Sharedprefs(this);

        mywebview = (WebView) findViewById(R.id.inspiration_webview);

        String url = share.getSubUrl()+"/sources.html";

        mywebview.getSettings().setJavaScriptEnabled(true);
        mywebview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);    //desperate try
        final Activity activity = this;
        mywebview.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                // Activities and WebViews measure progress with different
                // scales.
                // The progress meter will automatically disappear when we reach
                // 100%
                activity.setProgress(progress * 1000);
            }
        });
        mywebview.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode,
                    String description, String failingUrl) {
                Toast.makeText(activity, "Error loading Suppliers list: " + description,
                        Toast.LENGTH_SHORT).show();
            }
        });

        mywebview.loadUrl(url);

    }
}

编辑:我现在已经添加了这个$​​ C $ C强制活动时切换到,不只是当它的创建,当你回到加载起始页。这有时也不会加载起始页。

I've now added this code to force load the start page when the activity is switched to, not just when it's created and when you go back. This ALSO sometimes doesn't load the start page.

@覆盖
保护无效onResume(){
    super.onResume();
    Toast.makeText(getApplicationContext(),onResume,
            Toast.LENGTH_SHORT).show();
    mywebview.stopLoading();
    字符串URL = share.getSubUrl()+/ sources.html;
    mywebview.loadUrl(URL);
}

@Override protected void onResume() { super.onResume(); Toast.makeText(getApplicationContext(), "onResume", Toast.LENGTH_SHORT).show(); mywebview.stopLoading(); String url = share.getSubUrl()+"/sources.html"; mywebview.loadUrl(url); }

在祝酒显示每次切换到该活动的时间,但开始页面仅在第一次。所有其他时间,该页面是空白的。我一定要拯救 mywebview 莫名其妙的的onPause()?我看不出什么毛病上述code。

The toast is shown every time I switch to this activity, but the start page only the first time. All the other times, the page is blank. Do I have to "save" mywebview somehow on onPause()? I just can't see anything wrong with the above code.

推荐答案

从文档的例子重建活动后,我仍然有这个问题。而且,有时候会后的HTML几行,有时半个屏幕后停止装载。

After rebuilding the activity from the example in the docs, I still got the problem. And also, sometimes it would stop loading after a few lines of html and sometimes after half a screenful.

在起始页有效的CSS单行引起了渲染没有任何错误消息打破。该网页在Chrome中工作得很好相同的电话,它指向网页视图中比较不完整的实现。

A single line in the valid CSS for the start page caused the rendering to break without any error message. The page worked fine in Chrome on the same phone, which points to the implementation of WebViews being incomplete in comparison.

由于人应答和抱歉浪费的时间。这太糟糕正确遵循的标准,程序,有缺陷你绊倒,使项目产生负面盈利。

Thanks to people answering and sorry for the time wasted. It's just too bad to follow the standards, program correctly, and have bugs trip you up and make a project negatively profitable.

如果谷歌的开发者要修补这个或至少触发一个错误,违规行为跨度:空{显示:无;}

If the Google devs want to patch this or at least trigger an error, the offending line was span:empty {display:none;}

这篇关于GoBack的()中的WebView追溯到几乎是一路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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