Umm...why not create the singleton with the ApplicationContext
obtained from getApplicationContext()? It will always be valid, no
matter what Activity or other class you are interacting with the
singelton instance from.

Alternatively, pass it to whatever static function you are calling to
get the instance of the singleton. That static function will return a
new or cached object as well as setting a private field in the
singleton with the correct context. If you are worried about keeping
around references to your Activities, which is a valid worry, then
never pass an Activity context, always pass the Application context.


Jonathan



On Mar 4, 9:54 am, TreKing <[email protected]> wrote:
> On Fri, Mar 4, 2011 at 8:38 AM, Jake Colman <[email protected]> wrote:
> > 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?
>
> Is there a reason you can't pass the Context as a parameter to the function
> that actually needs it?
> Or get access to the LocationManager at a higher level, where you have a
> Context, and then pass that a parameter?
>
> --------------------------------------------------------------------------- 
> ----------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> transit tracking app for Android-powered devices

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