On Sat, Feb 5, 2011 at 5:19 PM, AndroidDevTime <androiddevd...@gmail.com> wrote: > Where > should the application state for a Widget be maintained? In the > Application subclass or in the Widget itself.
Neither. Ideally, an app widget has no "state" outside of data you maintain for your application as a whole, which hopefully is in a database or some other persistent store. The "Widget itself" has no meaning. If you mean AppWidgetProvider, it lives for milliseconds. If you mean the RemoteViews, they are read-only, and so you cannot store "state" in them to be read out later. The Application object will live only as long as your process lives, which could be for the same number of milliseconds that the AppWidgetProvider instance lives. Hence, anything related to an app widget that you want to live for more than an eye-blink should be in a persistent store or be re-retrievable from the OS. If you want to cache stuff in an Application object or static data members, in the off chance your process sticks around long enough to be useful, that's cool, just watch out for garbage collection issues. > I have decided to put > the state of the App Widget in an app subclass but not sure if this is > right, given I can't very well initialize everyting in the > Application.onCreate() method. Anything slow enough to cause a problem probably should be processed by an IntentService, or possibly an AsyncTask kicked off by the Application (I have never tried an Application-spawned AsyncTask). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android 2.3 Programming Books: http://commonsware.com/books -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en