Guys, Great answers, all. Thank you.
Please allow me to abstract this up one level. I am coming to Android development with many years of C++ experience on many platforms so I have a good understanding of development and OO. I am relatively new, however, to Java and Android. I am struggling a bit with the scope of objects and how that works with respect to the application as a whole and activities/services/receivers in general. If I create an instance of a singleton from within an activity/service/receiver, am I correct that that same instance is available to the other components of my application? If so, then is it correct to say that all the components of my application share the same memory space. Incidentally, please correct me if I am using incorrect Android or Java terminology. If that is the case, how do I know (or should I even try to know) if my singleton instance has gone out of scope? Does it get destroyed when the last component of my application has been killed by Android? Is there a way for me to know that? Do I care? The symptom that I am observing with my application is that my singleton instance has been recreated. But since my service thinks it has already initialized the singleton with the necessary data and that data has not changed. So the newly initialized singleton is not being reinitialized to the saved values. Is the correct Android paradigm to have my singleton's constructor check whether there is a saved preference and to reconstruct itself with those values if it exists? If so, then I can have the service save those values in shared preferences since the service certainly knows when it is being stopped. Thanks for all your help. ...Jake >>>>> "MM" == Mark Murphy <mmur...@commonsware.com> writes: MM> On Tue, Mar 22, 2011 at 7:32 PM, Jake Colman <col...@ppllc.com> wrote: >> If my appwidget is sitting on the homescreen and displaying it's >> data might it still be killed even though it's active? MM> Your app widget is not "sitting on the homescreen". It is never MM> "sitting on the homescreen". MM> Your app widget, from the standpoint of your code, is a MM> BroadcastReceiver (AppWidgetProvider), perhaps with some other MM> classes (e.g., an IntentService). MM> What *is* "sitting on the homescreen" are Views, created based on MM> a definition you set up in the form of a RemoteViews. The MM> RemoteViews is transferred, via inter-process communication, from MM> your process to the home screen's process. >> I recognize that my service is killed the moment it is done with >> its work but does the same gold true for the appwidget's broadcast >> receiver? MM> Yes. This is true of all manifest-registered broadcast receivers. >> If the answer is yes, then is the apwidget display simply a >> statically drawn thing that is displayed on the screen even if the >> receiver is dead? MM> Absolutely. That is the entire point of an app widget. >> I am assuming that your answer to all of the above is: yes, my >> application might get killed. If so, how do I know when that is >> happening so that I can save my location information somewhere? MM> When you get your location information, save it, or just update MM> app widget's RemoteViews. >> How do I know when to restore it? MM> When you are called with onUpdate() in your AppWidgetProvider, MM> load your data, if needed. MM> -- MM> Mark Murphy (a Commons Guy) MM> http://commonsware.com | http://github.com/commonsguy MM> http://commonsware.com/blog | http://twitter.com/commonsguy MM> _The Busy Coder's Guide to Android Development_ Version 3.5 Available! MM> -- MM> You received this message because you are subscribed to the Google MM> Groups "Android Developers" group. MM> To post to this group, send email to android-developers@googlegroups.com MM> To unsubscribe from this group, send email to MM> android-developers+unsubscr...@googlegroups.com MM> For more options, visit this group at MM> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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