I have a FragmentPagerAdapter used to show about 6 tabs, all of which load their data from a web server. One of the tabs contains a WebView that loads an image from my server. The server side costs of generating the image are high, and thus I want to reduce the number of calls to reload the WebView. For the non-WebView tabs, I have been able to save my state (for those, just a simple array) and restore them as tabs get swiped through.
Problem:
Solutions Considered:
It sounds like the old behavior of WebView.saveState() would have been perfect...
The problem appears to be that you are wiping out your own results.
While you need a new WebView
on a configuration change, you do not need a new WebView
otherwise. And, if you already have the WebView
, you do not have to tell it to do anything.
So, I'd try this:
WebView
that you create in onCreateView()
in a data member of the fragmentonCreateView()
if that data member is null
loadUrl()
if you inflated the layout(if you are creating the WebView
in Java code, replace "inflate the layout" with "create the WebView
via its constructor")
If the contents of the fragment is more than the WebView
, you will also need to hold onto the root view that you inflated in a data member, so you can return that from onCreateView()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With