由于崩溃来自android内部库,并且最可疑的代码位于下面,因此崩溃仅在Oreo设备中出现
ChatAlertDialogFragment chatAlertDialogFragment = ChatAlertDialogFragment.getInstance(bundle);
chatAlertDialogFragment.show(getFragmentManager(), ChatAlertDialogFragment.class.getSimpleName());
注意:当我们用支持片段管理器替换简单的片段管理器时,它就可以正常工作。
这是例外日志
07-18 14:59:45.103 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.aspiringminds.amcat.debug, PID: 13679
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.unFocus(android.view.View)' on a null object reference
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5207)
at android.view.ViewGroup.removeViewAt(ViewGroup.java:5170)
at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1561)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1611)
at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2204)
at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2148)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2049)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:718)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
ChatAlertDialogFragment
类代码
public class ChatAlertDialogFragment extends DialogFragment {
public static ChatAlertDialogFragment getInstance(Bundle bundle) {
ChatAlertDialogFragment chatAlertDialogFragment = new ChatAlertDialogFragment();
chatAlertDialogFragment.setCancelable(false);
chatAlertDialogFragment.setArguments(bundle);
return chatAlertDialogFragment;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.setStyle(android.R.style.Theme_Holo_Light_Dialog_MinWidth, android.R.style.Theme_Holo_Light_Dialog_MinWidth);
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
return dialog;
}
}