5

I am making a widget similar to that of YouTube and default Weather/News one. I have a view flipper in which I add layouts dynamically (which contains an ImageView and a TextView) using:

remoteViews.addView(R.id.viewFlipper, itemViews);

The problem is that I need to load images from a URL in that layout. What is the best way to do this ?

I have a Lazy List loader but that does not work on RemoteViews and even after modification I think it is not correct to update the widget for every image which might drain the battery too fast.

Thanks in advance.

Afzal
  • 357
  • 4
  • 12

1 Answers1

0

I'm not sure entirely what you are referring to without a code sample, but the Android Developer's website has some great information. Since you want to mimic the behavior of the YouTube app, you'll want to use a collection layout like AdapterViewFlipper or StackView. All of these require a RemoteViewsService and RemoteViewsFactory. Your best bet is to have a background Service running that will asynchronously download the images you want.

I think it is not correct to update the widget for every image which might drain the battery too fast

This depends entirely on how often you are updating your set of images. If the app refreshes its set every 12 hours, then I cannot imagine any significant battery drain assuming there are no memory leaks/ background tasks constantly running. If you are still concerned, you could create a ContentProvider that stores all of these images and then only after the entire set is downloaded to you tell all Views in the collection to update with the new content.

Tom
  • 6,947
  • 7
  • 46
  • 76