I am Using Following Code to stop reloading the web page
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);
}
and used android:configChanges="orientation|keyboard|keyboardHidden" in my manifest file
But when i run it and change orientation of my phone.
The page still get reloaded and progressbar started showing and never dismiss.
can anyone tell me whats wrong in this??
By default the activity is recreated at orientation change. But you can change it by setting
android:configChanges="keyboardHidden|orientationin the declaration of your activity in AndroidManifest.xml and overriding theonConfigurationChanged()method of the activity class.