On Feb 5, 2:33 pm, Mark Murphy <[email protected]> wrote:
> On Sat, Feb 5, 2011 at 5:19 PM, AndroidDevTime <[email protected]> 
> wrote:
> > Where
> > should the application state for a Widget be maintained?  In the
> > Application subclass or in the Widget itself.
>

true, but what I was thinking is an app widget that is reflecting the
application's state.

> 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.
>
Alright, but what I really want is the app widget reflects the state
of the app.  It makes no sense for the Widget to store the app state
off for the app to me.  Perhaps the service, but then again it is
really the state of the app, not the state of the widget (although the
widget reflects it), nor is it the state of the service.  So the point
is each component needs to reference the application level status
state, (even if it just needs it for few milliseconds), and yes it
needs to be stored, but it also needs to be kept in a synced/singleton
manner at all times.

> 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.
>
registerReceiver(null, Intent) would be under 5 seconds for sure?  I
have not seen any guarantees related to android functions.

> 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/commonsguyhttp://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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to