[android-developers] Re: Scope of Singletons

2011-03-23 Thread Jake Colman
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

Re: [android-developers] Re: Scope of Singletons

2011-03-23 Thread Kostya Vasilyev
23.03.2011 16:14, Jake Colman пишет: 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

Re: [android-developers] Re: Scope of Singletons

2011-03-23 Thread Mark Murphy
On Mar 23, 2011 9:15 AM, Jake Colman col...@ppllc.com wrote: 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? For the life of the process, yes. If so, then is it

[android-developers] Re: Scope of Singletons

2011-03-23 Thread Jake Colman
I use the following standard paradigm for singletons: private static MyClass instance = null; public static MyClass getInstance() { if( instance = null ) instance = new MyClass(); return instance; } If my application gets killed by Android, as can be expected, can I reasonably assume

Re: [android-developers] Re: Scope of Singletons

2011-03-23 Thread Mark Murphy
On Wed, Mar 23, 2011 at 12:37 PM, Jake Colman col...@ppllc.com wrote: If my application gets killed by Android, as can be expected, can I reasonably assume that when the application is restarted that instance is reinitialized to null?  In other words, when Adroid invisibly kills and restarts

Re: [android-developers] Re: Scope of Singletons

2011-03-23 Thread TreKing
On Wed, Mar 23, 2011 at 11:37 AM, Jake Colman col...@ppllc.com wrote: public static MyClass getInstance() { if( instance = null ) instance = new MyClass(); return instance; } I hope that was a typo. If that's your actual code, you have bigger problems.

[android-developers] Re: Scope of Singletons

2011-03-23 Thread Kenny Riddile
On 3/23/2011 12:37 PM, Jake Colman wrote: I use the following standard paradigm for singletons: private static MyClass instance = null; public static MyClass getInstance() { if( instance = null ) instance = new MyClass(); return instance; } If my application gets killed by

Re: [android-developers] Re: Scope of Singletons

2011-03-23 Thread TreKing
On Wed, Mar 23, 2011 at 11:56 AM, Kenny Riddile kfridd...@gmail.com wrote: instance == null, not instance = null...right? Precisely. - TreKing http://sites.google.com/site/rezmobileapps/treking -

[android-developers] Re: Scope of Singletons

2011-03-23 Thread Jake Colman
T == TreKing treking...@gmail.com writes: T On Wed, Mar 23, 2011 at 11:37 AM, Jake Colman col...@ppllc.com wrote: public static MyClass getInstance() { if( instance = null ) instance = new MyClass(); return instance; } T I hope that was a typo. If that's your

[android-developers] Re: Scope of Singletons

2011-03-22 Thread Jake Colman
T == TreKing treking...@gmail.com writes: T On Tue, Mar 22, 2011 at 5:58 PM, Jake Colman col...@ppllc.com wrote: But does that mean that my singleton can be taken out of scope as well? T Scope is not the appropriate term. But if your process gets T killed, it takes

Re: [android-developers] Re: Scope of Singletons

2011-03-22 Thread TreKing
On Tue, Mar 22, 2011 at 6:32 PM, Jake Colman col...@ppllc.com wrote: Do I have to assume that my application might get killed? Yes. Not might. Will ... eventually. If my appwidget is sitting on the homescreen and displaying it's data might it still be killed even though it's active?

Re: [android-developers] Re: Scope of Singletons

2011-03-22 Thread Mark Murphy
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? Your app widget is not sitting on the homescreen. It is never sitting on the homescreen. Your app

Re: [android-developers] Re: Scope of Singletons

2011-03-22 Thread Dianne Hackborn
On Tue, Mar 22, 2011 at 4:32 PM, Jake Colman col...@ppllc.com wrote: Do I have to assume that my application might get killed? If my appwidget is sitting on the homescreen and displaying it's data might it still be killed even though it's active? I recognize that my service is killed the