I have a widget that fills a list with some downloaded information, which includes an image downloaded from a given URL.
I want to display this image using setImageViewBitmap with a bitmap created from the URL. I can successfully create the bitmap, but i face a problem:
When i use:
itmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(item.getPosterUrl()).getContent());
remoteViews.setImageViewBitmap(R.list_item.poster, bitmap);
The image is successfully shown on the widget list, however the download is kind of slow (and in general this should be done in any network operation) so i wanted to use a thread to perform the download on background while user can see the rest of the list.
My problem is that when i use the thread, the download is performed well but the remoteViews is not updating the image. I tried also with a Handler with the same result.
Maybe I need something as runOnUIThread but i didn’t find a similar method for widget.
What can I do?
Thanks in advance,
Step #1: Download the image.
Step #2: When the download is complete, then update the app widget, using the image, via a
RemoteViewsand anAppWidgetManagerUPDATE
To clarify a bit, you cannot reliably download something directly in an
AppWidgetProvider—onUpdate()is called on the main application thread, and so the download may take too long.However,
onUpdate()can delegate its work to anIntentServicethat downloads the image and updates the app widget itself.AppWidgetProvideris a place to update an app widget, but other code in your app can update the app widget too. Just have yourIntentServicecreate theRemoteViews, obtain anAppWidgetManager, and do the update.