Re: [android-developers] Custom Dialog example may be incorrect
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. dada...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com 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 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
Re: [android-developers] Custom Dialog example may be incorrect
You definitely should not be using getApplicationContext() for showing UI -- in fact that is completely backwards, because the application context is the Application object, which exists the entire duration of the process, but explicitly does NOT allow for UI (since it is not associated with a UI context, that is an activity). On Sun, Nov 22, 2009 at 5:14 PM, TreKing treking...@gmail.com wrote: 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. dada...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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
[android-developers] Custom Dialog example may be incorrect
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 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