0

I'm building an Android app which connects to an Amazon RDS DB via a Node.js server.

My DB includes a certain table of items. Each row in this table includes the item's id, a name, a short description, and a link to an image. Whenever the user opens up the app, the first thing they see, is this data in card views.

My question(s) is this: What is the correct approach to load images (and other data)? Do I just load it again and again each time the user opens up the app? Do I somehow cache it, so the images won't have to be downloaded again next time? And if I cache the images, what happens if the content of the url changes, and now contains a different image? do I check for checksum, download, and cache the image again? And what about the rest of the data? If it's a text, do I just load it each time the user opens up the app?

Also, what is the best way to perform the download itself? Do I use a Loader? an AsyncTask? Some other type of threading? I'm new to multi-threaded programming so any info would help here. Thanks!

Cookienator
  • 637
  • 1
  • 7
  • 25
  • The default in Android is to use `HttpUrlConnection` to load data in an AsyncTask. Then, create a separate task that takes the image url and loads the image whenever it is needed. I would recommend checking out [Retrofit](http://square.github.io/retrofit/) for calling your API and [Picasso](http://square.github.io/picasso/) for getting images from a URL however, as they allow you to avoid the pain of writing those AsyncTasks. – Weava Sep 20 '16 at 15:46
  • Check several libraries are avaiable to making the caching easy for you ,if you are planning to do it in out own you need to take care of lot of things ,so better use existing libraries http://stackoverflow.com/questions/19995007/local-image-caching-solution-for-android-square-picasso-vs-universal-image-load – surya Sep 20 '16 at 16:06

3 Answers3

1

Depends on problems you are solving. I can recommend two common libs, they are simple and reliable.

Picasso : 

http://square.github.io/picasso/

Glide :

https://github.com/bumptech/glide

You can even do this by yourself by using default networking and decoding streams. Or use UniversalImageLoader, but I think using Picasso or Glide is the best solution.

Yurii Tsap
  • 3,554
  • 3
  • 24
  • 33
0

I would suggest to use https://github.com/square/picasso library

Usage:

Picasso.with(context).load("https://i.stack.imgur.com/E5w9Z.jpg").into(imageView);

Main page:

http://square.github.io/picasso/

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
0

I think if you worried about image caching then you may go for Glide.

But if you worried about image quality then you may go for Picasso.

I prefer to use Glide. For better differentiation you may look at here.

Md Sufi Khan
  • 1,751
  • 1
  • 14
  • 19