0

我有一个片段,我在其中打开底部对话框

private void openImageDialog() {
        NavController navController = findNavController(view);
        Timber.d("%s", navController.getCurrentDestination());
        navController.navigate(SettingUpProfileFragmentDirections.openImageDialog(resourceFile));
}

在 BottomSheetDialogFragment 我有

private void openGallery() {
        Intent intent = new Intent(ACTION_PICK, EXTERNAL_CONTENT_URI);
        startActivityForResult(intent, SELECT_IMAGE_REQUEST);
}

返回对话框后,我只是像这样关闭对话框

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (requestCode == SELECT_IMAGE_REQUEST && resultCode == RESULT_OK && data != null) {
         dismiss();
     }
}

当我再次尝试从 Fragment 打开对话框时,我得到了下一个异常

java.lang.IllegalArgumentException: Navigation action/destination com.xxx:id/openImageDialog cannot be found from the current destination Destination(com.xxx:id/editProfilePhotoDialog)
        at androidx.navigation.NavController.navigate(NavController.java:938)
        at androidx.navigation.NavController.navigate(NavController.java:875)
        at androidx.navigation.NavController.navigate(NavController.java:861)
        at androidx.navigation.NavController.navigate(NavController.java:1150)
        at com.xxx.ui.fragment.SettingUpProfileFragment.openImageDialog(SettingUpProfileFragment.java:143)
        at com.xxx.ui.fragment.SettingUpProfileFragment.onProfileImageClick(SettingUpProfileFragment.java:130)
        at com.xxx.ui.fragment.SettingUpProfileFragment.lambda$onViewCreated$4$SettingUpProfileFragment(SettingUpProfileFragment.java:96)
        at com.xxx.ui.fragment.-$$Lambda$SettingUpProfileFragment$2Q5hfVos3CTEjzzPhfVwb1h-ZBs.onClick(Unknown Source:2)
        at android.view.View.performClick(View.java:7448)
        at android.view.View.performClickInternal(View.java:7425)
        at android.view.View.access$3600(View.java:810)
        at android.view.View$PerformClick.run(View.java:28305)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

来自方法的日志openImageDialog()显示我仍在对话片段上 D/SettingUpProfileFragment: Destination(com.xxx:id/editProfilePhotoDialog)

我的想法是,由于从中打开画廊,我仍在对话中,但不知道它如何影响导航。关于如何解决这个问题的任何想法?

4

1 回答 1

0

替换dismiss()Navigation.findNavController(getActivity(), R.id.mainNavigationFragment).popBackStack()并解决了问题。但仍然好奇为什么dismiss()没有按预期工作。

于 2021-01-11T19:21:24.813 回答