From 1de1fdeb4778930eeb149d0b81b21301c4862baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B6=9B?= Date: Mon, 20 Jul 2020 11:58:45 +0800 Subject: [PATCH] android: navController check null --- .../main/java/pub/doric/DoricPanelFragment.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java b/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java index a738aa20..2ed4e573 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java @@ -85,8 +85,11 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { argument.putString("source", source); argument.putString("alias", alias); argument.putString("extra", extra); - getNavController() - .navigate(R.id.action_doricPanelFragment_to_doricPanelFragment, argument); + NavController navController = getNavController(); + if (navController != null) { + getNavController() + .navigate(R.id.action_doricPanelFragment_to_doricPanelFragment, argument); + } } @@ -95,14 +98,19 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { if (getActivity() == null || getActivity().isFinishing()) { return; } - if (!getNavController().popBackStack()) { + NavController navController = getNavController(); + if (navController != null && navController.popBackStack()) { if (getActivity() != null) { getActivity().finish(); } } } + @Nullable private NavController getNavController() { + if (getView() == null) { + return null; + } return Navigation.findNavController(getView()); }