On Sun, Oct 10, 2010 at 2:44 PM, Chuck Lega <chuck.l...@gmail.com> wrote:
> I often run into the following dilemma: I need some singleton-like
> object in my app (typically some central manager-like thing) and this
> object needs a context for various things. This means that I either
> have to pass a context to all methods needing one or have some sort of
> init-pattern to the object. Neither is pretty I think. What is the
> correct way of doing this? Or is this simply (even the definition of)
> a Service?
>
> Anyone have any thoughts on this?

You really really really need to be careful about putting a Context in
a static data member, as you can run into memory leaks if Android
wants to destroy that context later. I recommend that you either pass
in the Context as needed, convert it into a Service that your
activities bind to, or make it a custom Application object (which is a
Context, though you may still find times when you'll need an
Activity's context).

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 3.0.1 Available!

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

Reply via email to