On Wed, Jun 23, 2010 at 12:36 PM, Kostya Vasilyev <[email protected]> wrote: > On the other hand, using a service is definitely the way to go for widgets > that fetch data from the Internet or some other way that can take a long > time.
There are (at least) three costs to doing work in the app widget itself versus an IntentService: 1. The app widget provider might get killed if it takes too long (~10 seconds). 2. Tying up the main application thread, even for fairly short bursts, will cause your app's activity, if visible to freeze up. Even really short bursts (e.g., 250ms) can cause your UI to appear "janky" if the user is actively using it. 3. Your code is running at foreground priority, and so it will steal CPU cycles from anything truly in the foreground, such as a real-time game. Since app widget providers themselves cannot maintain state, they inevitably have to use flash storage, even if just for reads. Doing a simple database query is perhaps fast enough that you could get away with doing it in the app widget provider itself. However, if you write to flash, you want to move that to the IntentService, because flash writes can get crazy slow (see the Zippy Android Apps presentation from Google I|O 2010). And, of course, network I/O may take indefinitely long. Hence, unless the app widget functionality is trivially small, you're probably going to want an IntentService, task killers be damned. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to *Advanced* Android Development_ Version 1.6 Available! -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en

