M
M
mike1142012-01-09 08:11:57
Android
mike114, 2012-01-09 08:11:57

Which dialog call option do you use in Android?

One question has been tormenting for a long time - what is the best way to call a dialog in Android and why?
The SDK offers two options: showDialog(Dialog dialog) and showDialog(int dialogId [, Bundle bundle]), where the second one is marked as deprecated, and it is recommended to use a similar fragment method, but the essence remains the same.
In the first case, I can create complex dialogs, fill them from the database, but when the screen is rotated, they disappear forever.
In the second case, the dialog does well when rotated, but is created once during the lifetime of the Activity, so it is difficult to display actual data if the dialog needs to be raised more than once and with different initial data.
What do you think about this? Maybe I missed something?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
serso, 2012-01-09
@serso

I use

android.app.AlertDialog
with his
android.app.AlertDialog.Builder
Fully controlled dialog - you can use three buttons (you can hang different names), hang your view, listeners on button presses, etc. It is created every time anew - dynamically.
And in order for the dialog not to disappear, it is enough to specify a:configChanges="orientation" for the actvity where it was called.

F
falstaf, 2012-01-09
@falstaf

therefore, there are difficulties with displaying actual data if the dialog needs to be raised more than once and with different initial data

In this case, a preliminary call to removeDialog(id) , which is not very pretty.
In general, DialogFragment - IMHO, the best and most convenient option.

S
serso, 2012-01-09
@serso

You may ask why it is not recommended to write like this?
I just ran through the guide , but I didn’t find anything intelligible except for a remark, which, by the way, does not explain the reasons for this behavior.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question