Note that this will only work single-threaded. Add the synchronized keyword to the method and make the static data member volatile to make it safe for multi-threaded access.
(a problem I ran into with WakefulIntentService, which is why this issue is fresh in my mind...) On Wed, Jun 1, 2011 at 10:34 PM, Streets Of Boston <[email protected]> wrote: > The code below will work fine for a singleton: > ... > private static MyObject myObject = null; > public static MyObject getMyObject() { > if (myObject == null { > myObject = new MyObject(); > } > return myObject; > } > > Note that variable won't be 'reset' to null. There is nothing to reset when > your process is killed. It is gone, nohting left. > > When a new process is started, i.e. the process that will run your app > again, then the static fields are all properly initialized (in this case, > 'myObject' to the value 'null'). > > > -- > 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 -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android 3.0 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

