1

I am displaying a profile photo inside an image view, which is pulled along with user detail from a website with Volley Post request. I am working on offline preview feature (which will display profile data with profile image offline for all searched history)

And I am not sure, what is the best way to do that:

  • By saving encoded string in SQLite db and pull and decode when needed?
  • By saving decoded image on Phone OR SD card memory?

It would be great if someone also shares pros and cons (like performance and resources issues) for both cases.

Atlas_Gondal
  • 2,512
  • 2
  • 15
  • 25

3 Answers3

1
  1. Storing big chunks of data in a database is not very productive.
  2. For binary data, there's BLOB data type. Base64 encoding-deconding is redundant here.
  3. You can take a ready-to-use image downloader, such as Glide or Picasso. They are already shipped with cache feature.
Miha_x64
  • 5,973
  • 1
  • 41
  • 63
0

I think it is easier to store the image on the filesystem, in the private area of the app, and if you need the image related to some data, just store the file name as a field in the database.

Dealing with BLOB fields requires a lot of boilerplate code and I don't think there is much benefit of doing it that way.

Juan
  • 5,525
  • 2
  • 15
  • 26
0

Picasso is best way to manage your scenario.

Firstly you don't have to use Volley Post request to fetch images details. you just need to pass the url to Picasso and its will manage it you you.

Secondly you also don't need to store images data locally for cache features as Picasso has already its own cache feature.

Here is how you can add Picasso library to your project

Firstly, Download the latest JAR or grab via Gradle:

compile 'com.squareup.picasso:picasso:2.5.2'

Then fetch image and add image to imageView

Picasso.with(context)
.load(imageUrl)
.networkPolicy(NetworkPolicy.OFFLINE)
.
.into(imageView, new Callback() {
@Override
public void onSuccess() {

}

@Override
public void onError() {
    //Try again online if cache failed
    Picasso.with(context)
            .load(getImageUrl())
            .error(R.drawable.header)
            .into(imageView, new Callback() {
        @Override
        public void onSuccess() {

        }

        @Override
        public void onError() {
            Log.v("Picasso","Could not fetch image");
        }
    });
}
});

Here is complete implementation

Ali Ahsan
  • 460
  • 3
  • 13