Coil: Image Caching Issue

Created on 1 Jul 2020  路  3Comments  路  Source: coil-kt/coil

Describe the bug
When I run my App on the Phone it has a different behavior when compared to the emulator.
Emulator:

  • Loads my Images awesomely.
  • Sets the Cards Background Color awesomely.
  • The problem comes when I rotate the device, It looses the color of my CardView.

You may find my code on this repository DC-Villains_Fix_Coil_Image_Loading

Phone:

  • Doesn't load images at start unless I keep scrolling and coming back.
  • Sets the Cards Background Color awesomely
  • When I rotate the device at start id doesn't loose color of the CardView. only after having scrolled a bit

Expected behavior
I want to have the same behavior across all devices in which:
I would open the app:

  • Load the Image from the network, convert it into a bitmap.
  • Set the Card's background according to the palette I choose
  • Cache the Image and Color extracted from the Image by the Palette so that it is always available.

To Reproduce
Run the app on an emulator and wait for the images to load, rotate the device 2 or 3 times to see changes. Scroll a bit then rotate the phone again 2 or 3 times
Test the same on a physical device as well.

Logs/Screenshots

  1. This is how it looks when I open the App on the Emulator

device-2020-06-29-044215

  1. This is how it looks after rotation

device-2020-07-01-214117

  1. This is how it looks on my phone(Samsung Galaxy S6 running Android Nougat 7.0)

Screenshot_20200630-154444

Version
minSdkVersion 19
targetSdkVersion 30
compileSdkVersion 30
coil version '0.11.0'

bug

Most helpful comment

Not sure if this is relevant. I wanted to post because I observed different behaviors on Phone vs Emulator. But my experience was quite opposite. I spent 3 hours on emulator figuring out why image is not loaded. Then (luckily) I tried on real device and it was all good there.

All 3 comments

Thanks for the detailed report. It's possible for the Android Emulator to have different behaviour from the device due to how the system is emulated, however I'd expect the real device to be the one to work correctly. I'll take a look at this and see what I can find.

Not sure if this is relevant. I wanted to post because I observed different behaviors on Phone vs Emulator. But my experience was quite opposite. I spent 3 hours on emulator figuring out why image is not loaded. Then (luckily) I tried on real device and it was all good there.

@doilio The card background isn't being set because you're setting the background colour inside the Transformation. If the image is returned from the memory cache, Transformation.transform won't be run. When you rotate the phone twice, the list of images will likely still be cached in the memory cache.

Check out this recipe for safe ways to compute the palette that will work if the image is returned from the memory cache.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RubenGonzalezGonzalez picture RubenGonzalezGonzalez  路  6Comments

gastsail picture gastsail  路  4Comments

ZacSweers picture ZacSweers  路  4Comments

Starscream9559 picture Starscream9559  路  7Comments

vegeta2102 picture vegeta2102  路  6Comments