简体   繁体   中英

Android: Retrieve images from Server

I am building an android application which requires displaying images as a flip-view which will be retrieved from server. I have considered two approaches

  1. Retrieving images from server URL and then displaying OR
  2. Storing the image in db at server(MySQL) and then retrieving it from sq-lite on android application

My question is, which approach will be better considering everything (performance, etc.)?

Any other better approach is also welcome :)

This depends upon your Application and products you are going to display using Images, If they are not updated frequently then it would be better to use caching for faster user experience but if data is regulatory updated and previous data is keep getting filtered then always load using network.

Another approach you can just store latest 10-20 entries in your Database and as soon as you opens the application he can see some data and new data gets downloaded, this approach keeps users engage don't leave them your app just because every time they see loading.

For Image caching purposes there various good libraries avaible which are stable solutions for multiple images downloading as well as caching purposes Eg UniversalImageLoader , picasso , Volley

  1. You store images locally and load then to your app from local storage (This happens in a background thread)

  2. You update the local storage by fetching the images in background, when needed, and then trigger the load from local storage (This also happens in a background thread)

This way you won get ANR's (application not responding) because of slow or missing internet connection, and you will be able to show images without connection at all.

A good approach could be store locally images locally on demand, and keep it on cache, if the image changes on future you can invalidate your cache and download a new image.

I have used in a project a library that helps me a lot with to download the image in background, allows you also load image from cache automatically if stored previously or invalidate the cache. The library is android-query and here is an example of how you could use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM