Zelig
Zelig

Reputation: 157

Modal dialog box

I want to do in an Android application what I can do very easily in a "common" Java application : in a function triggered by a click on a menu item, I want to display a modal dialog box in which either the user can enter a text or choose between two or three answers (typically "yes", "no" and "cancel"). Once the user has made his input, the function can continue according to the choice made.

With the Fragment class, I can display the dialog box. The problem is that it only appears after the completion of the function triggered by the user's click. This means that the code depending on the user input has to be executed in the class derived from the Fragment class. And this has two disadvantages : - it's more complex because a communication between the two objects has to be implemented, - the reuse of the class is not easy since it's customized to communicate with only one class. Of course, it's possible to implement multiple communications towards as many class as we want, but the complexity will be even worse.

Is it possible to do what I want to do in a more simple way?

Thanks in advance for the time you will spend trying to help me.

Upvotes: 0

Views: 567

Answers (2)

Ron
Ron

Reputation: 24233

Using a modal dialog is not allowed in android applications due to reasons like

  • A phone could go unattended for a long time. If a modal dialog pops up in that time, the app will be blocked, until the user attends the phone and dismisses the modal dialog. This will amount to loss in valuable processing time.
  • Even when the user is operating the phone, an app should not be blocked as a phones hardware configuration is far less than desktops and every millisecond of processing time is important.

I may be missing other points but these are the important ones.
So you should consider using callbacks to continue processing users input.

Upvotes: 1

Related Questions