Most listeners/callbacks that I use are annonymous inner classes in
methods that already take a Context as a parameter.  In that case I
just make the parameter "final" and use it from the callback method
without it having to receive a Context directly.


On Oct 13, 3:15 am, Chuck Lega <chuck.l...@gmail.com> wrote:
> Ok, I may be a bit vague, but say I want an utility class to do some
> common stuff, including resources and shared prefs. Then I need a
> context. If I put a SharedPreferenceListener into the class, I am lost
> if I want to do something using a context when receiving the
> callbacks.
>
> This is how I think about it now: singleton object with init(ctx).
> Init is called from App, i.e. with appctx.
> What would typically this (app)context not be suitable for?
>
> Sorry for deviating...
>
> /Chuck
>
> On 12 Okt, 21:03, TreKing <treking...@gmail.com> wrote:
>
>
>
> > On Tue, Oct 12, 2010 at 1:37 PM, Chuck Lega <chuck.l...@gmail.com> wrote:
> > > For instance, say I register a listener in the singleton. The callbacks to
> > > the listener does not contain a context, and I am back at square one
> > > again...So, I guess init-ing the singleton with a context is the simplest
> > > way,
> > > and making it a service the most robust/correct(?).
>
> > What listeners and callbacks are we talking about? You may want to provide
> > more, um, context (har har) about how you're using a singleton, callbacks,
> > listeners, and the Context. There's probably a better way than initializing
> > the singleton with the Context object.
>
> > And making your singleton a Service may not necessarily be the most robust
> > /correct - it depends on what you're trying to achieve with this singleton.
>
> > ---------------------------------------------------------------------------­­----------------------
> > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> > transit tracking app for Android-powered devices- Hide quoted text -
>
> - Show quoted text -

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