我正在使用 Android O Developer Preview 的模拟器上对此进行测试。在以前的版本中,一切正常。
我得到了一个 LoginFragment,它在登录处理时显示“请稍候”进度对话框。
public class ProgressDialogHud extends DialogFragment {
private String messages;
public static ProgressDialogHud newInstance(String message) {
ProgressDialogHud dialog = new ProgressDialogHud();
// ...
return Dialog;
}
}
public class LoginFragment extends Fragment {
private DialogFragment mProgressDialog;
private void login() {
mProgressDialog = ProgressDialogHud.newInstance( "..." );
mProgressDialog.show( getActivity().getSupportFragmentManager(), "PROGRESS" );
}
private void onLoginFinished() {
mProgressDialog.dismiss(); // NullPointerException here because inside Fragment (DialogFragment extends Fragment) the FragmentManager is null
}
}
我做了一个小调试会话,发现 DialogFragment 使用 2 个不同的 FragmentManager 来显示和隐藏。在显示片段时,管理器不为空,但在隐藏时为空。
这是堆栈跟踪
有任何想法吗?