我有一个在片段中成功启动的DatePickerDialog。当方向发生变化时,应用程序崩溃。 logcat输出表明NPE与DatePickerFragment的onDismiss一起发生。我在这里缺少什么?
这是部分DatePcikerFragement文件:
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
public DatePickerFragment() {
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
...
DatePickerDialog picker = new DatePickerDialog(getActivity(),
this, year, month, day);
return picker;
}
public void onDismiss(final DialogInterface dialog) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(CardViewActivity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
super.onDismiss(dialog);
}
}