My guess is the example is wrong (or at least outdated). If you search the
forums you'll find that getApplicationContext() seems to do nothing but
cause problems like these and is best avoided altogether.

I would love to hear from a Google Engineer about the intended use of this
function and what's the correct way to use it - or if it should be used at
all.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking


On Sat, Nov 21, 2009 at 8:20 AM, Kevin S. <[email protected]> wrote:

> I spent quite a long time trying to get my first custom dialog box to
> work, following the example in the Android Dev Guide.
>
> Specifically:
>
> http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
> -------
> Context mContext = getApplicationContext();
> Dialog dialog = new Dialog(mContext);
>
> dialog.setContentView(R.layout.custom_dialog);
> dialog.setTitle("Custom Dialog");
> -------
>
>  I kept getting a badtokenexception whenever I tried to show the
> dialog.
>
>  Eventually I found a forum posting which suggested changing it to:
>
> new Dialog(this);
>
>  Which made the problem go away.
>
>  My question is if the example is incorrect, or was the code not
> intended to be used in an Activity method?
>
>
> -Kevin
>
>
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

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