我有一个关于webview的以下场景
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view_tutorial);
mWebView = (WebView) findViewById(R.id.webView1);
mWebView.setWebViewClient(mWebViewClient);
mWebView.setInitialScale(0);
mWebView.setVerticalScrollBarEnabled(false);
mWebView.requestFocusFromTouch();
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
Button btnGo = (Button) findViewById(R.id.button1);
btnGo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String url = "http://www.google.com";// here goes my server url with https://...... for authentication
showProgressDialog("Loading");
mWebView.loadUrl(url);
}
});
}
private void showProgressDialog(String title) {
if(mProgress == null || !mProgress.isShowing()){
mProgress = ProgressDialog.show(this, title, "Please wait...", true,
true, new OnCancelListener() {
public void onCancel(DialogInterface pd) {
finishActivity();
}
});
mProgress.setCanceledOnTouchOutside(false);
mProgress.setCancelable(true);
}
}
private void finishActivity() {
if(mWebView!=null){
finish();
}
}
private final WebViewClient mWebViewClient = new WebViewClient() {
public void onPageStarted(WebView view, String url,
android.graphics.Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.d("test", "page started");
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d("test", "page should override called");
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
if (mIsLoadingSigninPage) {
mIsLoadingSigninPage = false;
dismissProgressDialog();
}
Log.d("test", "page finished");
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
mIsLoadingSigninPage = false;
dismissProgressDialog();
Log.d("test", "page error received");
super.onReceivedError(view, errorCode, description, failingUrl);
finishActivity();
}
};
private void dismissProgressDialog() {
if (mProgress != null && mProgress.isShowing()) {
mProgress.dismiss();
mProgress =null;
}
}
//这是下面第3点的log cat
03-07 07:31:20.977: D/test(1431): page started
03-07 07:31:22.788: D/test(1431): page should override called
03-07 07:31:22.887: D/test(1431): page started
03-07 07:31:24.496: D/test(1431): page finished
确定,
并且WebView显示空白屏幕,未调用onReceivedError。 这是logcat
和
答案 0 :(得分:0)
它肯定会调用页面启动和页面完成,因为将调用onReceivedError: -
- 点击任何链接(如果互联网不存在)然后应该覆盖url将抛出一个错误,它将处理
-on活动开始或调用webview时
对于onRecievedError未处理的所有异常,您必须检查http状态