Reputation: 691
I am working on a mobile application with phonegap and jquery mobile for android. It is working properly but it takes so much time to get data from server.
I want to cache its pages so if user come back on same page he can view same page. I am using jquery mobile caching code but it is not working.
I am using this code data-dom-cache="true"
for cache
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.appView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
super.loadUrl("file:///android_asset/www/find.html");
}
Upvotes: 1
Views: 1491
Reputation: 691
Cache is not working in my app so I stored all json data in localstorage by doing this
window.localStorage.setItem("ALL_USERS",JSON.stringify(data));
where data
is json object I retrieve from server.
And next time i retrieve data from localstorage
window.localStorage.setItem("ALL_USERS",JSON.stringify(data));
users = JSON.parse(users);
This solution solved my problem hope it will help others.
Thanks
Upvotes: 1
Reputation: 231
Call below code in onCreate() method of your Android application activity file:
super.appView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
The above method uses cache if content is there, even if expired (eg, history nav). If it is not in the cache, load from network
Please look WebSettings constants for cache settings :
http://developer.android.com/reference/android/webkit/WebSettings.html
Upvotes: 0