11.01.2011 23:10, John Gaby пишет:
Broadcast receivers are only guaranteed to stay around long enough for
>  their onReceive to complete. They can be destroyed after that, and a new
>  instance will be created if needed later.
>
Given that it creates a new instance of my AppWidgeProvider class for
each call, is there a way to have persistent data associated with my
widget?  That is how can I store data that will still be present on
the next call (other than writing it to disk)?

Well, there isn't a special mechanism just for widgets that I know of.

You can:

- Use SharedPreferences;

- Cache data in a static (singleton), since the process just might stick around longer than the receiver;

- Combine the above two methods;

- For anything beyond a certain level of complexity, it's probably a good idea to delegate at least some of your widget logic to a service (the Wikipedia wiget sample does this, although for a different reason).

--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
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

Reply via email to