-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
As noted by Android Studio, each fragment tag in xml should be replaced by a FragmentContainerView. This issue concerns Jetchat and Jetsurvey as both use the fragment tag in conjunction with Navigation UI. However, simply replacing the tag leads to a crash because findNavController() throws a RuntimeException when invoked during the onCreate(). As discussed in this issue tracker (https://issuetracker.google.com/issues/142847973), the NavController can be safely referenced via the NavHostFragment. I'm proposing the replacement of the tags to appease Android Studio and the supplemental replacement of the findNavController() calls with an appropriate workaround. We would expect to see the following lines replace the findNavController() in each relevant MainActivity:
val navHostFragment: NavHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController: NavController = navHostFragment.navController
I am happy to see the Navigation UI documentation has been updated to reflect this solution as Android Studio's warning was dangerous in this scenario. Thanks!