Some notes on android dialogs

Here are some notes on fragment dialogs

This is not overly useful for simple dialogs.

putting up a simple android alert dialog

Search for: putting up a simple android alert dialog


public void alert(String title, String message)
{
   AlertDialog alertDialog = new AlertDialog.Builder(this).create();
   alertDialog.setTitle(title);
   alertDialog.setMessage(message);
   alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
      }
   });
   alertDialog.show();      
}

and use the dialog fragment methods to show and respond to the dialog. This approach may replace the older method of regiestering dialog ids for the sake of recreating them during configuration changes.

In other words the activity will not recreate the dialog if the activity is flipped.


Simple ones that dont' track state

//old kind
Managed dialogs: activites manage state for dialogs

//new kind
Fragment Dialogs: Fragments contain and manage state for dialogs

This leaves only the dialog fragments as the approved way to show dialogs.

Dialogs and setCancelable

Search for: Dialogs and setCancelable

In android you can prevent a dialog from closing on back

Search for: In android you can prevent a dialog from closing on back

by default the setcancelable is true.

You can set this to false to prevent a dialog from closing on back. This may be useful if you have an asynctask that you want to complete and want to give a hint to the user.

The home button seem to work fine taking you to the home screen.

for example, if you go home while a dialog is being displayed, and an asynctask has finished and wants to close its dialog, then the state of the dialog won't allow its dismissal!

So from a UI perspective there are certain things you cannot do when the UI has stopped

In Android does dismissing a dialog fragment remove the fragment?

Search for: In Android does dismissing a dialog fragment remove the fragment?