2

我正在使用支持库来创建使用片段的对话框。

我有以下代码来显示和关闭对话框:

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.d("Create", "Create");
    setContentView(R.layout.activity_report);
    init();
    addListeners();
    addhandlerListener();
    super.onCreate(savedInstanceState);
}

private void showDialog(final Class<?> classs) {
    if (classs.equals(AddressValidateProgress.class)) {
        addressValidateProgress = AddressValidateProgress.newInstance();
        addressValidateProgress.show(getSupportFragmentManager(), null);
        Log.d("counter", "+1");
    }
    if (classs.equals(GPSSearchProgress.class)) {
        showDialog(gpsSearchloadId);
    }
}

private void dismissDialog(final Class<?> classs) {
    if (classs.equals(AddressValidateProgress.class)) {
        FragmentTransaction ft = getSupportFragmentManager()
                .beginTransaction();
        ft.remove(addressValidateProgress).commitAllowingStateLoss();
        addressValidateProgress = null;
        Log.d("super", addressValidateProgressId + ":dismissed");
    }
    if (classs.equals(AddressChooseDialog.class)) {
        FragmentTransaction ft = getSupportFragmentManager()
                .beginTransaction();
        ft.remove(addressChooseDialog).commitAllowingStateLoss();
        addressChooseDialog = null;
    }
    if (classs.equals(GPSSearchProgress.class)) {
        dismissDialog(gpsSearchloadId);
        Log.d("super", gpsSearchloadId + ":dismissed");
    }
}

如果我以纵向模式启动应用程序,我可以正常使用对话框,我什至可以旋转屏幕并重建对话框。
问题是,如果我启动应用程序旋转屏幕并单击打开对话框的按钮,我会得到一个异常:

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
4

1 回答 1

0

找到解决方案。

这是由声明的静态处理程序引起的

于 2012-07-14T15:33:40.067 回答