• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AlertDialog don't wait for user to respond

 
Dov Ezra
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I don't understand the hang of using Dialogs on android.
after I call AlertDialog.show(), execution don't stop and wait for the user to respond.
it just continue to the next statement. but I need the user to click the yes button before I continue.
that why I need this dialog in the first place.

I know that the AlertDialog have listeners for clicking the positive and negative buttons, but the program don't wait for one of those to be execute. What am I missing here?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blocking the UI thread is a bad idea, which is why dialogs don't block. You'll need to restructure you code so that no code is executed after the dialog is shown. Any further code execution would then be triggered by the user clicking "yes" or "no".

Android will actually terminate activities that block the UI thread after 10 seconds or so.
 
Dov Ezra
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's one paradigm shift from desktop applications.

if you cannot have modal dialogs that wait for user responce, why would you use dialogs at all?
It may be simpler just to add new activity with yes and on buttons and call it for result.
 
Michael Rivera
Ranch Hand
Posts: 132
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dov Ezra wrote:Hi,

I don't understand the hang of using Dialogs on android.
after I call AlertDialog.show(), execution don't stop and wait for the user to respond.
it just continue to the next statement. but I need the user to click the yes button before I continue.
that why I need this dialog in the first place.

I know that the AlertDialog have listeners for clicking the positive and negative buttons, but the program don't wait for one of those to be execute. What am I missing here?


Activity lifecycle matters, so i would give you a quick solution but not a great one, you can disable the back button !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic