3

I have one sample application which has WebView supporting html5 features, i have one website which stores offline data and retrieves offline stored data, but whenever i force close the application it looses all saved data.

Is there anything extra ordinary i am suppose to do to handle force close?

Thanks in advance :)

RPB
  • 16,006
  • 16
  • 55
  • 79
  • what type of data and caching mechanism are you using? Are you using js Objects, local Storage, or some db mechanism in android os? – Andres Gallo Sep 20 '12 at 09:53
  • using same as described in http://stackoverflow.com/questions/5899087/android-webview-localstorage – RPB Sep 20 '12 at 09:56
  • That is enabling DOM local and session storage. Are you using localStorage API in your web view's javascript? If you are not you may not be storing anything after all. if('test' in localStorage)alert('s'); else localStorage.test = 's'; alert(localStorage.test); With the above code in the web view you should see the two alerts. Once the first time and two after everytime if the data did get stored – Andres Gallo Sep 20 '12 at 10:00
  • i am using localStorage APIs i think – RPB Sep 20 '12 at 10:02
  • on default browser its working as i expect even if i do force close also – RPB Sep 20 '12 at 10:03
  • yes. What I mean is on the web view, the same rules apply. If you force close the web view in an app. Once you reopen that same webview context, the storage should remain – Andres Gallo Sep 20 '12 at 10:04
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/16915/discussion-between-rinkalkumar-and-andres-gallo) – RPB Sep 20 '12 at 10:05

1 Answers1

4

I too had this problem and found this strange behavior of Activity and WebView:

If you have more than 1 web views declared in your layout xml, force close/reboot will not persist cached offline data.

So solve this issue, I kept only 1 web view in the layout xml and other web views I added dynamically into view group. This prevent the offline data loss. Hope this helps.

PC.
  • 6,870
  • 5
  • 36
  • 71