我正在使用支持库来创建使用片段的对话框。
我有以下代码来显示和关闭对话框:
@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
答案 0 :(得分:0)
找到解决方案。
它是由声明的静态处理程序
引起的