我正在使用以下代码停止重新加载网页
public class MainActivity extends Activity {
WebView webView;
@Override
protected void onSaveInstanceState(Bundle outState) {
WebView webView1 = (WebView)findViewById(R.id.webView);
webView1.saveState(outState);
}
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView)findViewById(R.id.webView);
String url="http://www.google.com";
if (savedInstanceState != null)
{
((WebView)findViewById(R.id.webView)).restoreState(savedInstanceState);
}
else{
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
String name = MainActivity.this.webView.getTitle();
TextView t=(TextView)findViewById(R.id.title);
t.setText(name);
Toast.makeText(getApplicationContext(), name, Toast.LENGTH_SHORT).show();
}
});
final Activity activity = this;
final ProgressDialog progressDialog = new ProgressDialog(activity);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
final ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setUserAgentString("Android");
webView.setWebChromeClient(new WebChromeClient()
{
public void onProgressChanged(WebView view, int progress) {
progressBar.setVisibility(View.VISIBLE);
progressDialog.setProgress(0);
activity.setProgress(progress * 1000);
progressDialog.incrementProgressBy(progress);
if(progress > 75)
progressBar.setVisibility(View.GONE);
}
}
);
webView.loadUrl(url);
}
并android:configChanges="orientation|keyboard|keyboardHidden"
在我的清单文件中使用
但是当我运行它并改变手机的方向时。
页面仍然会重新加载,进度条开始显示并且永远不会关闭。
谁能告诉我这有什么问题?