Spawning off the "Dialog box without title" thread to discuss the pros and
cons of storing Context as a member vs passing a parameter. Here's the last
bit of the discussion from that thread:

On Mar 26, 1:24 pm, TreKing <treking...@gmail.com> wrote:
> On Sat, Mar 26, 2011 at 2:32 PM, Archit Jain <dce.arc...@gmail.com> wrote:
> > Dialog alertDialog = new Dialog(getApplicationContext());
>
> Never use getApplicationContext() - it's pointless and doesn't work for
> Dialogs. I'm surprised you're seeing anything.

It's not pointless, and please stop telling people that.  :-)

You just have to know when to use it.  Use it when you need to store a
context in an object that lives longer than an instance of an activity
or service, but don't want to leak that activity or service.  The
application context is perfect for that.

On Sun, Mar 27, 2011 at 2:25 AM, Doug <beafd...@gmail.com> wrote:

> It's not pointless, and please stop telling people that.  :-)
>
> You just have to know when to use it.  Use it when you need to store
> a context in an object that lives longer than an instance of an activity or
> service, but don't want to leak that activity or service.  The application
> context is perfect for that.
>

I suppose that is true. Though IMO a Context is not something that should be
stored in an object that outlives an Activity or Service. If you need a
Context, one is usually readily available wherever you happen to be and can
be passed as a parameter.

Do you have a good example of when storing a Context like this is a good
idea? I'm just curious.

On Sun, Mar 27, 2011 at 10:16 AM, Kostya Vasilyev <kmans...@gmail.com>
 wrote:

> 27.03.2011 19:05, TreKing пишет:
>
> Do you have a good example of when storing a Context like this is a good
>> idea? I'm just curious.
>>
>
> I do. Singletons.
>
> Or, to use a more simple name, "manager" or "utility" classes that provide
> reusable functionality, which needs to be available to more than one Android
> application component.


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