'Android how to execute two dialogs in a certain order

I have coded two dialogs in Android, which individually works. But the first dialog is rapidly replaced by the second dialog without permetting an answer.

My question is : how to force an order of execution (my code can wait for an answer on the first dialog).

My solution could be to exchange dialogs execution order to be sure that the second dialog is the first launched. But I wonder if the is a better solution ? I have seen a lot of Android examples on the site, but not really answering my question.



Solution 1:[1]

There are two solutions.

First use dialogFragment with Navigation, and upon input from dialog 1, navigate to dialog 2. That is how your first dialog will not be overriden by dialog 2.

Second you can use call back in dialog1, which will be invoked on the input in dialog1, and in your fragment, get that call back and show second dialog.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kashif Masood