android - Restoring Application State on Phonegap -


i've develop android app phonegap, app need swicthing on toggle button, user can close app , running in background service. problem when close app , app again, initial state toggle button off. so, question how can saving/restroring app state on android , phonegap?

i've read save & restoring webview in embedded phonegap app , still don't understand restorefrompreferences() , savetopreferences(out) can help?

*sorry bad english

as @geet said, localstorage need store datas , retrieve them later. according phonegap website, localstorage provides access w3c storage interface. can read here : http://dev.w3.org/html5/webstorage/#the-localstorage-attribute.

to save toggle button position :

<script>  function ondeviceready() {  // set togglebutton false default var togglebutton = window.localstorage.getitem("togglebutton"); if (togglebutton==null) window.localstorage.setitem("togglebutton", 'false');  // set default state if (window.localstorage.getitem("togglebutton")=='true') {     $('#onoffswitch').attr("checked", "checked"); }  // switch onoffswitch event $('#onoffswitch').on('change', function(){     if ($(this).prop('checked')) {         window.localstorage.setitem("togglebutton", 'true');     } else {         window.localstorage.setitem("togglebutton", 'false');     } });  }  </script> 

make sure in html toggle element (form me checkbox) isn't checked default :

<input type="checkbox" name="onoffswitch" id="onoffswitch"> 

about pause , resume, can perform actions when these events called. :

<script>     document.addeventlistener("resume", yourcallbackfunction, false);     document.addeventlistener("pause", yourcallbackfunction, false); </script> 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -