0

I'm developing an app which is made of SingleActivity&Fragments.
The project flow is below.

Project flow

enter image description here
The navgraph is below.

Navigation flow

enter image description here

RegisterPhotoFragment has a photo button. If i click the button, it show the CameraOrGalleryBottomSheetDialog by using navigate(actionid).
In the CameraOrGalleryBottomSheetDialog, I can take a photo or get a image url from gallery. For the process, I'm using setFragmentResultListener in RegisterPhotoFragment and setFragmentResult in CameraOrGalleryBottomSheetDialog.
But the problem is, I can't get the image uri from CameraOrGalleryBottomSheetDialog in RegisterPhotoFragment and I realized that RegisterPhotoFragment is just made by using ViewPager2 in BeginningFragment not navigate(anctionid). So, i didn't use navigate(actionid) to go to the RegisterPhotoFragment.
Therefore, I changed the navigation flow like below.

Second Navigation Flow

enter image description here

I restarted my app and it happened a crash.

java.lang.IllegalArgumentException: Navigation action/destination mypackage:id/action_registerPhotoFragment_to_cameraOrGalleryBottomSheetDialog cannot be found from the current destination Destination(mypackage:id/beginningFragment) label=BeginningFragment class=,mypackage.presentation.ui.beginning.BeginningFragment

because i added the RegisterPhotoFragment res/navigation/navGraph but i didn't use navigate(actionid). If i use naviagte(actionid), I can only see the screen of RegisterPhotoFragment. So, i didn't use it.

Finally, I decided to make a RegisterPhotoNavHostFragment and it has only FragmentContainerView and the Navigation Flow is changed again like below.

enter image description here

Sadly, I thought it works but it didn't. the same crash occured.
How can i make it? is this idea wrong?

CodingBruceLee
  • 657
  • 1
  • 5
  • 19

1 Answers1

0

Okay, I solved this problem. One thing that i missed was that i have to create the RegisterPhotoNavHostFragment instead of RegisterPhotoFragment when i create the FragmentStateAdapter for ViewPager2 in BeginningFragment.

before

private fun getFragmentsForViewPager2() = arrayListOf(
    RegisterPhotoFragment.getNewInstance(),
    RegisterNicknameFragment.getNewInstance(),
    RegisterGenderFragment.getNewInstance()
)

after

private fun getFragmentsForViewPager2() = arrayListOf(
    RegisterPhotoNavHostFragment.getNewInstance(),
    RegisterNicknameFragment.getNewInstance(),
    RegisterGenderFragment.getNewInstance()
)

the idea works well.

CodingBruceLee
  • 657
  • 1
  • 5
  • 19