Tobio
Tobio

Reputation: 255

Android webview retain form data when orientation changes

How to retain the form data in the webview after the change the orientation ? I have used onSaveInstanceState() and I have restored the previous state using restoreState(savedInstanceState). This successfully restores the previous state before the change in orientation but it does not restore the data in the text box of the form in the webview.

What should be done to retain the data in the text box of the forms in webview after the change in orientation ?

Note: I would not be using android:configChanges="keyboardHidden|orientation" as I need keyboard input for my application after orientation changes.

Thanks in advance.

Upvotes: 5

Views: 795

Answers (1)

gheese
gheese

Reputation: 1200

As the WebView has been destroyed and then recreated you will need to repopulate the form. You can do this by injecting javascript into the web view

for example to update text displayed by HTML element id status

wevView.loadUrl("javascript:document.querySelector('#status').innerHTML = 'some text'");

Upvotes: 1

Related Questions