Hari,

Yes, I am familiar with singletons.  As a mtter ofr fact, the class that
I am creating is going to be a singleton - which is why I don't want to
construct it with a context.

So your suggestion is that I extend the Application class using the
singleton pattern?  And my extension saves 'this' (the context) as a
static member of my singleton?  So now I have to see how to extend the
application class.

Thanks.

...Jake


>>>>> "HE" == Hari Edo <[email protected]> writes:

   HE> One alternative is to look for, or create, a public singleton.  A
   HE> public singleton is a class that (1) ever only has one instance,
   HE> and (2) that instance can be located from anywhere by means of a
   HE> static method.

   HE> One candidate for singleton status is Application -- it is a
   HE> Context, and you expect there'll only be one of them.  In your
   HE> extension of Application, have the constructor save 'this' to a
   HE> static field, and have a public static method to get the saved
   HE> reference.  Voi la, you can now get a useful Context from
   HE> anywhere.  Most apps don't use an Application extension, but you
   HE> can use this pattern on pretty much any class.

   HE> On Mar 4, 9:38 am, Jake Colman <[email protected]> wrote:

   >> I'm sure that this is a basic question that must have been
   >> answered a 100 times but I googled to no avail.  Maybe I am going
   >> about this the wrong way.
   >> 
   >> I am creating a class that is not an Activity or a Service.  I
   >> need that class to be able to get a hold of, for example, the
   >> Location Manager.  If I had a context I would call
   >> 
   >>    (LocationManger)context.getSystemService(...)
   >> 
   >> How do I obtain a context in this situation?
   >> 
   >> I would prefer not passing in the context to the class
   >> constructor.  Am I fundamentally misunderstanding this
   >> environment?
   >> 
   >> --
   >> Jake Colman -- Android Tinkerer

   HE> -- 
   HE> You received this message because you are subscribed to the Google
   HE> Groups "Android Developers" group.
   HE> To post to this group, send email to [email protected]
   HE> To unsubscribe from this group, send email to
   HE> [email protected]
   HE> For more options, visit this group at
   HE> 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 [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