Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

I have the EA daily deals widget installed on my second home screen. The widget is basically a rotating banner of deals in the Play store. Since it is constantly rotating the displayed banner I assume that it is draining more battery than a static widget (it also doesn't have any options for rotation or network updates).

My question is, are widgets suspended when they are not being displayed i.e. when I am on the first or third home screen? Or, does it depend on the implementation?

*Using the stock launcher on Android 4.2.

share|improve this question

2 Answers 2

In my experience, widgets keep running even when the phone is locked, or a different home screen is selected.

share|improve this answer

Short answer

Widgets don't actually "run" themselves, like normal apps do. The widget host (i.e. the home screen app, or the lock screen) is in charge of drawing all the widgets. The widget provider (part of the app) tells the host what layout to give each widget, and how often it wants the widget to update. There's nothing running to "suspend", regardless of whether the widget is visible or not.

Resource cost

While the widget doesn't "run", it still has to be shown on the screen. Every widget therefore makes the host process (i.e. the launcher) a little more expensive in CPU usage and memory. Every time the widget is redrawn (whenever it changes, or whenever the home screen animates), it makes that redraw use a few more CPU cycles. Also, once the provider has told the host what layout to use, the host has to use RAM to remember the widget's layout. Because it's the host storing that information and drawing the widget, it counts towards the host's battery use and memory footprint, not the app's. How much cost it is depends on the host (that is, which launcher you use), as well as on how complex the layout is.

For this reason, Android puts strict limits on the complexity of each widget's layout, as well as the total size of all images used in the widget. The limit depends on the pixel size of the screen, so on a it's huge. If you have lots of widgets, all using large images or complex layouts, the launcher process can take up quite a lot of memory, so it's more likely to be killed while you're running an app in the foreground. The effect of this would be to cause a short delay when going to the home screen.

Services

Of course, it's also possible for a background service to keep giving the host (home screen) a new layout for the widget. This is how (say) an email widget can be updated when you have new emails. Such a service would run whether the widget is currently displayed or not: there's no way for the service to tell.

For example, if you have an email widget, the normal email service should run at intervals to check mail, and update the widget during the course of its normal run if there's any new mail. In this case, the only cost of the widget is the small cost inside the host, because the service would be running anyway to sync your mail in the background.

Having a rotating list (such as in your example) shouldn't in itself make you think there's a service always running in the background, for this reason:

Lists and rotating banners

The interface that widget providers use to specify what the layout should be allows them to give a list of items. For example, this might be a list of email messages, or a list of calendar appointments, that you can scroll through. The provider can also have the home screen rotate through the list automatically. The YouTube widget uses this, for example, so that the widget can keep showing new videos without the provider having to keep changing the layout. If your widget uses this facility, then the home screen only runs any extra code when it's time to rotate the list.

Which cost is important?

The resource cost of a normal widget (that is, one that doesn't have an insanely complicated layout and doesn't use huge bitmaps) is tiny compared to the cost of a background service to update it with new information. To take your EA daily deals example, you don't need to worry about the widget rotating, but rather how the daily deals are updated. Does the service run all of the time, or every few minutes; or does it actually run once a day to fetch the new deals? Does it stop itself if there's no internet connection? Will it wake the device from sleep to do an update? These are all things the app author had to program, and that users can't control (and don't need to know about directly), but they have a much bigger effect on the widget's cost than anything the launcher does.

TL;DR

Drawing widgets, even rotating widgets, is cheap: too cheap to measure the cost. The real cost is whatever app runs in the background to update the widget with new data. How often that app runs depends on the app, and doesn't depend on whether the widget is displayed at any given time.

share|improve this answer
    
Very comprehensive answer, Dan -- good job! Seems to explain all details involved (at least as far as they are interesting to the user). As a side-effect it also explains why one should restrain oneself from "overloading homescreens" with widgets :) –  Izzy Jun 1 '13 at 18:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.