How To Prevent Webview Auto Refresh When Screen Rotation
Solution 1:
There is more than one approach to tackle this problem.
The easy way out is to add android:configChanges="orientation|screenSize"
to the relevant Activity
in your manifest. By setting this flag you tell Android to not destroy the Activity
and that you're going to handle all orientation changes (if any) yourself.
The more modern approach would be to put the WebView
inside a Fragment
and make it retain its instance, using the setRetainInstance(true)
flag. The hosting Activity
will still get destroyed on orientation changes, but the Fragment
containing the WebView
will simply be detached and re-attached, without the need to re-create itself. You can find an example of this feature in the API demos. Keep in mind that the support library offers a pre-Honeycomb compatible implementation of fragments, so don't be fooled by the API level of the 'regular' Fragment
class.
Solution 2:
Highlighting @kirgy comment, You have to add orientation|screenSize
to your manifest if your API > 3.2 , It wont work without it in some cases.
Solution 3:
Add android:configChanges="orientation"
to your manifest file to prevent restarts when the screen orientation changes.
like::
<activityandroid:name=".MyActivity"android:configChanges="orientation|screenSize"android:label="@string/app_name">
See this for some references.
Post a Comment for "How To Prevent Webview Auto Refresh When Screen Rotation"