A
A
Andrey Sklyarov2016-06-06 12:46:53
Android
Andrey Sklyarov, 2016-06-06 12:46:53

WebView - how not to reload the page when the screen is rotated?

Given: an application with one host Activity and many Fragments. In one of the fragments, the content is loaded into the WebView. I would like to make sure that the page does not reload from the web every time the user rotates the device.
Stackoverflow offers this answer:

public class MyFragment extends Fragment {
  
  ...
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
    ...
    
    if (savedInstanceState == null) {
      mWebView.loadUrl(URL);
    } else {
      mWebView.restoreState(savedInstanceState);
    }
  }
  
  @Override
  public void onSaveInstanceState(Bundle outState) {
    mWebView.saveState(outState);
  }
}

The problem is that restoreState just as stupidly pulls the page from the Internet (checked on 4.4.2 and 6.0.1).
Found another solution: www.devahead.com/blog/2012/01/preserving-the-state... It boils down to disabling the automatic re-creation of the Activity and saving the WebView itself in addition. But that's not an option at all since I have ~30 fragments and manually handle each onConfigurationChanged... Hmm...
Doesn't this work with fragments? Or is that how it should be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
aol-nnov, 2016-06-06
@aol-nnov

Склонен считать, что это проблема мобильного хромиума (который и есть вебвью)
типа такой
у меня на киткате (SGS3) была такая проблема просто при переключении табов браузера, а на CM11 на этом же аппарате - не было.

S
Severus256, 2016-06-06
@severus256

Проблема в пересоздании активити. Кажется на андроид это не решить без костылей

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question