>
> The original question was regarding AlertDialog.show() vs.

AlertDialog.showDialog(), and not involving Activity.showDialog()

which has no corresponding .show().


I think it was AlertDialog.show() vs Activity.showDialog(int), since he
says:

If you don't call .show and use showDialog from the activity ...


Plus, there is no AlertDialog.showDialog() ...


> this seems to imply that the answer to his original

question is that it's *never* safe to call AlertDialog.show() because

you can never be sure that the user won't change orientation while the

dialog is shown.


It is safe to use AlertDialog.show() if you're keeping a reference to the
dialog and will take care of dismissing it / re-showing it as necessary when
the Activity is destroyed / restarted. This is essentially what the Activity
does for you.

Unless you have a good reason not to, just stick with showDialog(int) and
let it do the work for you.

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


On Sat, Jan 9, 2010 at 2:20 PM, Coco <[email protected]> wrote:

> Great answer, Sean. Thanks.
> The original question was regarding AlertDialog.show() vs.
> AlertDialog.showDialog(), and not involving Activity.showDialog()
> which has no corresponding .show(). Assuming that these services share
> implementations, this seems to imply that the answer to his original
> question is that it's *never* safe to call AlertDialog.show() because
> you can never be sure that the user won't change orientation while the
> dialog is shown. More likely is that I'm just missing something here
> but I just spend a few hours struggling with alert dialogs so it sure
> would be great to see a good simple example of how to safely use them.
>
> -Melinda
>
> On Jan 8, 9:55 am, Sean Hodges <[email protected]> wrote:
> > When you use Activity.showDialog() you are telling the parent activity
> > to manage the dialog that you create.
> >
> > From the API docs (
> http://developer.android.com/intl/fr/reference/android/app/Activity.h...)
> > ):
> > "A call to onCreateDialog(int) will be made with the same id the first
> > time this is called for a given id. From thereafter, the dialog will
> > be automatically saved and restored."
> >
> > When you rotate the phone, your parent activity is closed and
> > re-created. The showDialog() method tells the activity to
> > automatically re-create the AlertDialog as well.
> >
> > When you use AlertDialog.show(), you are effectively managing the
> > dialog yourself. This means that when the activity is closed and
> > re-created, you would have to make sure the dialog is dismissed and
> > displayed correspondingly; otherwise the activity *may* be destroyed
> > before the dialog has chance to close, and the internal reference to
> > it will be flagged as leaked.
> >
> > On Fri, Jan 8, 2010 at 5:15 PM, Michael Dorin <[email protected]>
> wrote:
> > > When creating an AlertDialog...I have noticed in some cases, if you
> > > invoke .show directly, you
> > > get a leaked dialog error when you rotate the phone.
> > > In other cases you don't.
> >
> > > If you don't call .show and use showDialog from the activity you don't
> > > see the leaked dialogs.
> > > Are there some cases when you can use .show?
> >
> > > Or is it just dumb luck if you don't see a problem?
> >
> > > -Mike
> >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Beginners" group.
> >
> > > NEW! Try asking and tagging your question on Stack Overflow at
> > >http://stackoverflow.com/questions/tagged/android
> >
> > > To unsubscribe from this group, send email to
> > > [email protected]<android-beginners%[email protected]>
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-beginners?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Beginners" group.
>
> NEW! Try asking and tagging your question on Stack Overflow at
> http://stackoverflow.com/questions/tagged/android
>
> To unsubscribe from this group, send email to
> [email protected]<android-beginners%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-beginners?hl=en
>
>
-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to