What I really want is what Windows calls a modal dialog box, i.e. one that must be closed by the user before they can do anything else. How can I get that effect in Android? It's particularly important for the first time someone runs my app because I want them to accept some terms and conditions, but I've got other cases where I need that as well.
At present I have a static class in my activity class as shown below, and I'm getting the dialog box to come up by calling the static method Create(...) on that class. But if the user just touches the activity behind the dialog box, or touches the search icon on the action bar, then the dialog box gets hidden. Can anyone help?
public static class SimpleDialog extends DialogFragment {
private static final String DialogLayoutIdString = "DialogLayoutId";
public static SimpleDialog Create(Activity activity, int Layoutid) {
FragmentManager fm = activity.getFragmentManager();
SimpleDialog about = new SimpleDialog();
Bundle args = new Bundle();
args.putInt(DialogLayoutIdString, Layoutid);
about.setArguments(args);
about.show(fm, "");
return about;
}
private int LayoutId;
private Activity activity;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
Bundle args = getArguments();
LayoutId = args.getInt(DialogLayoutIdString);
setCancelable(cancellable);
activity = getActivity();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
// various code to create the dialog box
AlertDialog alert = builder.create();
return alert;
}
}