Hi I am developing an app for a specific facebook page. The problem is that when i load URL in mywebview.loadURL(). The page opens successfully but the page always reload when the oreintation changes.

This problem only occurs for the above type Urls(i-e when I give the link of specific facebook page). But if i load URL as www.facebook.com or www.youtube.com or http://www.easyonlineconverter.com/converters/case_conveter.html no any page reload occurs as I have set android:configChanges="orientation|screenSize". Even If I give URL of any website with its specific page ,no page reload occurs when orientation changes.

Page reload only occurs in case of specific page of Facebook. I tried by loading URLs of difference facebook pages , every time facebook page reloads on orienataion changes. How can I prevent facebook page reload when orientation changes?

Dani AI

Generated

Short summary tied to the thread: observed that a specific Facebook page inside a WebView reloads when device orientation changes even though the activity declares android:configChanges="orientation|screenSize". Two separate root causes must be distinguished: (A) the Android activity is being recreated by the system, or (B) the webpage itself detects orientation and performs a reload. By default Android recreates activities on configuration changes; declaring configChanges changes that behavior and makes onConfigurationChanged run instead. (developer.android.com)

Quick way to confirm which case occurred is to log lifecycle callbacks (onCreate/onDestroy/onConfigurationChanged). If onCreate runs on rotation, treat it as a system recreation and persist WebView state. The built-in APIs are saveState/restoreState (use in onSaveInstanceState/onCreate), but the docs warn they don’t preserve display data fully — treat them as partial help and always fall back to reloading the last URL if needed. Example:

@Override
protected void onSaveInstanceState(Bundle out) {
  super.onSaveInstanceState(out);
  webView.saveState(out);
}

@Override
protected void onCreate(Bundle saved) {
  super.onCreate(saved);
  if (saved!=null) webView.restoreState(saved);
  else webView.loadUrl(lastUrl);
}

(developer.android.com)

If the activity is NOT recreated (onCreate not called) but the page still reloads, the reload is almost certainly page-driven (pages often listen for orientationchange and may call location.reload()). Neutralizing that requires injecting JavaScript after the page finishes loading (onPageFinished) and replacing or noop-ing reload handlers. Example (API 19+):

webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
  @Override public void onPageFinished(WebView v, String url) {
    v.evaluateJavascript(
      "window.onorientationchange=function(){}; if(window.location) window.location.reload=function(){};",
      null);
  }
});

This relies on evaluateJavascript / onPageFinished behavior. Use this only as a targeted workaround — it’s fragile for complex third‑party sites. (developer.mozilla.org)

About ’s suggestion to fetch the page locally: serving a local copy or intercepting requests via shouldInterceptRequest can avoid reloads, but it’s heavy, breaks dynamic/auth flows and is brittle for sites that use AJAX, cookies or OAuth. If caching is attempted, tune WebSettings.setCacheMode first; otherwise treat local-serving as a last resort. (developer.android.com)

Recommended steps (in order): confirm lifecycle logs; if system recreate, try saveState/restoreState or keep the WebView instance across rotations; if page-initiated, inject JS to disable orientation reloads; only then consider local caching/interception. Each option has trade‑offs when targeting a complex third‑party page like Facebook.

This will take a lot more code. Here's what you would have to do. Get the page into a local file so the fetch is local rather than from the Internet. This way there is no downside to the rotate. Frankly for the amount of work you have to put into this, you have to ask if it's worth the effort.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.