public class SuperActivity extends Activity
{
@override
public Context getApplicationContext()
{
throw new STOPIT();
}
public class STOPIT extends Exception
{
...
getMessage()
{
return "WTF DUDE, we discussed this"
}
}
}
public class SuperActivity extends Activity
{
.... onCreate
}
On Sep 24, 11:39 pm, TreKing <[email protected]> wrote:
> On Wed, Sep 22, 2010 at 9:41 PM, Nikhil <[email protected]> wrote:
> > why is that?
>
> The big reason is that there are UI-related functions that take Contexts but
> really expect Activities and if you use getApplicationContext() instead of
> your Activity as the Context for, say, creating a dialog, your app breaks.
> Search this group for "getApplicationContext" and you will find post after
> post of people running into this problem.
>
> Unfortunately, people keep falling into this trap because that's what's
> shown on the documentation samples for creating dialogs even though it is
> blatantly wrong, has been brought up repeatedly on this group, and would
> take about 5 seconds to fix.
>
> In other places where you don't need the UI it would work but it's
> completely unnecessary and redundant since getApplicationContext() is a
> member of the Context class, so anywhere you can use it implies you are
> already in or have access to a context anyway, so there's hardly a point to
> making the extra function call.
>
> I pretend that function doesn't exist.
>
> ---------------------------------------------------------------------------
> ----------------------
> 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