I am working on an Android home screen widget, which selects a random image url from an array of urls (obtained from firebase database), and displays that image. The widget updates every 30 minutes, and should, therefore, display a new image every 30 minutes or so.
I'm using Picasso to display the image from the url.
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
if (currentWidget.url.length() > 0) {
final RoundCornersTransformation transformation = new RoundCornersTransformation(50, 0);
Picasso.get().load(currentWidget.url).memoryPolicy(MemoryPolicy.NO_CACHE).transform(transformation).into(new Target() {
@Override
public void onBitmapLoaded (final Bitmap bitmap, Picasso.LoadedFrom from){
Log.d("PICASSO", "Bitmap Loaded");
views.setImageViewBitmap(R.id.appwidget_image, bitmap);
}
@Override
public void onBitmapFailed(Exception e, Drawable errorDrawable) {
Log.d("PICASSO", "Bitmap Failed");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
Log.d("PICASSO", "Bitmap Prepared");
}
});
}
I have tested the url, and it is updating regularly, and there is no logical error in the code, as the image is displayed sometimes. But, most of the times, even when the url updates and I get "Bitmap Loaded" in the console, the image in the widget does not update.