Coil: Force refresh an ImageView

Created on 9 Nov 2019  路  2Comments  路  Source: coil-kt/coil

Describe the bug
For example, when navigating to a fragment and calling ImageView.load() in onViewCreated() or onResume(), the image is being loaded correctly. However, when updating the image via an intent, the image in the ImageView is not being updated correctly despite calling ImageView.load() again.

What's weird too is that, when navigating to that same fragment via a BottomNav for example, the image gets refreshed properly.

To Reproduce
This can be reproduced using an ImageView and populate it with an image of a user, then start a pick image intent and update the photo of that user. When onResume() or onViewCreated() is called again, the image itself does not update.

Expected behavior
Coil should provide a force-refresh mechanism.

Library version
0.8.0

bug

Most helpful comment

Sounds like the image is being served from the memory cache. To fix this you can set a custom cache key using key. If the data changes, your cache key should change and it will miss the memory cache.

Alternately, you can skip reading/writing to the memory cache using:

```kotlin
imageView.load(data) {
memoryCachePolicy(CachePolicy.DISABLED)
}

All 2 comments

Sounds like the image is being served from the memory cache. To fix this you can set a custom cache key using key. If the data changes, your cache key should change and it will miss the memory cache.

Alternately, you can skip reading/writing to the memory cache using:

```kotlin
imageView.load(data) {
memoryCachePolicy(CachePolicy.DISABLED)
}

Thanks! Using the cache keys fixed it for me. There was another bug in my app that caused the activity to finish() before the image upload process was completed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

digitalheir picture digitalheir  路  4Comments

theScrabi picture theScrabi  路  5Comments

gastsail picture gastsail  路  4Comments

doilio picture doilio  路  3Comments

mario picture mario  路  3Comments