I have extended an ImageView in Android where I download an image, and when the image arrives I invalidate the view to get a redraw. If I use caching it's not working all the time, so I suspect that android is ignoring some invalidate commands if the system has just already repaint. Without cache it's slower and I get the drawing working, with cache it's faster and from time to time not all imageview get redrawn. (in the flow I get a first onDraw call by the framework, and when my image is ready I call postInvalidate and I get a second onDraw where I draw the bitmap on the canvas)
@Override
public void onLoadImage(Bitmap image, State state) {
_image = image;
postInvalidate();
}
@Override
protected void onDraw(Canvas canvas) {
if (_image == null) {
super.onDraw(canvas);
} else {
Rect destination = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());
canvas.drawBitmap(_image, null, destination, _paint);
}
}
the okHttpClient is configured like that (below), the onLoadImage take place in the onResponse callback from the networking library so not in the UI thread that's why I use postInvalidate instead of Invalidate
private static volatile OkHttpClient _httpClient = null;
public static OkHttpClient getHttpClient() {
if(_httpClient == null)
{
synchronized (Factory.class) {
if (_httpClient == null) _httpClient = new OkHttpClient.Builder().retryOnConnectionFailure(true).cache(getHttpCache()).build();
}
}
return _httpClient;
}
Does android ignore Invalidate on some occasions? any help would be welcome! Thx