Reputation: 408
I have created a new project and met with this warning while setting up bottom-tab navigation.
Gradle info
My Code:
private fun setupBottomNavigationBar() {
val navController = findNavController(R.id.nav_host_fragment)
supportFragmentManager.findFragmentById(R.id.nav_host_fragment)?.let {
val navigator = KeepStateNavigator(
this,
it.childFragmentManager,
R.id.nav_host_fragment
)
// This line gives me warning
navController.navigatorProvider += navigator
}
}
Tried solution:
// Solution 1
@SuppressLint("RestrictedApi")
private fun setupBottomNavigationBar() {
// Solution 2
// noinspection RestrictedApi
navController.navigatorProvider += navigator
Both are worked but I still don't know why I am getting this error. Is there anything anything else that I should know that might create the problem in future?
Any help is appreciated in advance!
Upvotes: 6
Views: 3179
Reputation:
You might avoid warning using the below code:
navController.navigatorProvider.addNavigator(navigator)
Upvotes: 7