I am currently using an AlertDialog to create a simple dialog in my application. The code I am using looks like this:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setTitle(DialogTitle);
builder.setItems(R.array.options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
reset();
break;
case 1:
exit();
break;
default:
break;
}
}
});
builder.show();
I have read that the best option may be to create a class that extends DialogFragment and then use my DialogFragment instead of my current implementation.
Can anyone confirm that this is the best solution, suggest something better and possibly give me an example?
Thank you.
You can override the
onConfigurationChanged(Configuration newConfig)
method of your activity to recognize the orientation change and restore theAlertDialog
if it was open. For this you will need the following tag in your activity definition in your manifestandroid:configChanges="orientation
. A good introduction can be found here.