DialogFragment failed. When calling startActivity ()

I have DialogFragmentone that was supposed to be simple, but it gave me some big problems, especially on Bean Jelly.

The application uses the network, and a dialog appears in it asking you to turn on Wi-Fi or cancel, and then close it. Therefore, it expands DialogFragmentand creates a view as:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog a = new AlertDialog.Builder(getActivity()).setCancelable(true).setTitle(R.string.dialog_title_disabled)
            .setMessage(R.string.dialog_text)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dismiss();
                        Intent i = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
                        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(i);
                    }
            }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        getActivity().finish();
                    }
            }).create();
    //a.setCanceledOnTouchOutside(false);
    return a;
}

If the user clicks "Yes", he rejects the dialogue and opens the activity of the wireless network settings. Or, if the user clicks the “Cancel” button, he simply closes all my actions, but on the Bean jelly, at any time when I click “Yes”, he opens the settings, but the application closes with the following error:

08-05 20:24:22.584: E/AndroidRuntime(2579): java.lang.IllegalStateException: Failure saving state: active SettingsDialogFragment{425dd550} has cleared index: -1
08-05 20:24:22.584: E/AndroidRuntime(2579):     at android.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1653)

There are several additional protocols showing the saved state of each fragment that was on my layout, and the number 2, which should have been SettingsDialogFragment, is simple null:

08-05 20:24:22.576: E/FragmentManager(2579):     #2: null

I tried not to reject the dialogue, but it crashed the same way.

I'm really not sure what's going on here ... Any ideas?


EDIT:

Operation code (this is normal activity, because the application targets ICS and higher):

private void showDialog() {
    SettingsDialogFragment diag = (SettingsDialogFragment) getFragmentManager().findFragmentByTag(DIALOG_TAG);
    if (diag == null) {
        diag = new SettingsDialogFragment();
        diag.show(getFragmentManager(), DIALOG_TAG);
    } else {
        if (!diag.isVisible())
            diag.show(getFragmentManager(), DIALOG_TAG);
    }
}

private void dismissDialog() {
    SettingsDialogFragment diag = (SettingsDialogFragment) getFragmentManager().findFragmentByTag(DIALOG_TAG);
    if (diag != null)
        diag.dismiss();
}
+5
source share
1 answer

Apparently, Google changed something from ICS to JB and rejected the dialog that I had to use:

dismiss();
getFragmentManager().beginTransaction().remove(frag).commit();

It seems that the dialogFragment is not removed from the OnDismiss fragment manager, as it was before, if someone wants to understand the source code and double-check on Communitiy, this will be super.

thank.

+7

All Articles