How to cache web content for offline mode?

2019-04-14 07:05发布

I'm developing a part of an app where application is supposed to read product-images and prices from online storage (website, which is to be built for this purpose only), make local storage of product-images and prices so that it could show the product-images and prices when it is offline. there will be a button; once it is pressed, its job is to synchronize the local cache. How could I implement this ? Any help would be highly appreciated.

Thanks in advance.

1条回答
萌系小妹纸
2楼-- · 2019-04-14 07:22

You can cache the bitmaps from a remote service using a Disk Cache, there is more information about how to do this on the Google developer site http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html

This will allow you to store the images and display immediately if there is no connection, or you want to load the images whilst loading the remote images.

Depending on what text you need to store you can associate the text with the images in the cache or alternatively set up an ArrayList with the data and store to disk. Some more details here Best Way to Cache Data in Android

Also there are tools around to ensure you are making the most of your network connections, such as the AT&T ARO tool, running this will help you to optimize your app by reducing your network calls to a minimum. See http://developer.att.com/aro

查看更多
登录 后发表回答