android - How do I preserve a web view's display state across activity destruction? -


i'm making android app that's complex javascript app embedded in web view. web view refreshes every time main activity's destroyed (ie due rotation, button press, etc).

to preserve state of web page, override onsaveinstancestate , onrestoreinstancestate:

  @override   protected void onsaveinstancestate(bundle outstate)   {     super.onsaveinstancestate(outstate);      // save state of webview     webview.savestate(outstate);   }    @override   protected void onrestoreinstancestate(bundle savedinstancestate)   {     super.onrestoreinstancestate(savedinstancestate);      // restore state of webview     webview.restorestate(savedinstancestate);   } 

this prevented refresh, fell short of preserving display state of web page, important me since user loses work in complex js app stored in display state.

i tried manually handle configuration changes overriding onconfigurationchanged. method preserved state rotation , other config changes, display state lost when user pressed android button (which destroys activity).

i'm considering storing web view on fragment that's preserved in bundle oncreate, i'm not sure if preserves display state.

i'm considering overriding ondestroy query javascript in web view current app state (say in blob or json format) , store in bundle (or in local sqlite blob), can't find synchronous method polling javascript state in android. send java object javascript maintains state of app android's addjavascriptinterface method, computing state of web app requires lot of work - don't want periodically poll state timer in web app.

any ideas on how preserve display state (as in dom elements dynamically created or text input) of web view across activity destruction? or how remember display state later re-construction?

i feel roadblock developers want make android apps powered centrally javascript embedded in web view.

you need treat code inside webview web application, , use storage features provided html. make sure enable them via websettings though (use this , this setting). alternatively, use similar functionality exposed via injected java object, way can modify stored data in java code.

state of dom , js in fact quite complex, , may involve network connections (via xhr , websockets), trying save dump losing effort.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -