I have single activity, FragmentHome contains viewpager2. Inside of viewpager there is FirstFragment.
when I want to navigate from FirstFragment to SecondFragment which is not in viewpager2
it throws
java.lang.IllegalArgumentException: navigation destination com.example.mymessangerfcm:id/action_FirstFragment_to_SecondFragment is unknown to this NavController
Dear community how to handle such navigation, and why the exception is thrown?
popUpTo and popUpToInclusive For example, if your app has an initial login flow, once a user has logged in, you should pop all of the login-related destinations off of the back stack so that the Back button doesn't take users back into the login flow.
You can use startActivityForResult(or broadcast/receiver) to get the result from the activity. Then use adapter. notifyDataSetChanged to refresh the fragment.
you should use the Global Action. When you are inside the viewpager, actually you are in a different navigation. So, you should make your action as Global. You can check the Global Action from official website :
https://developer.android.com/guide/navigation/navigation-global-action
After the making action as global, you can navigate like this;
findNavController().navigate(R.id.action_global_FirstFragment_to_SecondFragment)
Note: If you don't see global action after the doing it, rebuild your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With