Reputation: 729
I am stuck in this issue of back navigation button for long while, I have tried different methods but still the problem is not resolved
Here is the IMAGE
Defined in SelectLanguageFragment
private fun checkUserExist(){
val currentUser = auth.currentUser
val navOptions: NavOptions = NavOptions.Builder()
.setPopUpTo(`in`.jadu.anjuconsumerapp.R.id.consumerHomeFragment, true)
.build()
if(currentUser != null){
findNavController().navigate(`in`.jadu.anjuconsumerapp.R.id.action_selectLanguageFragment_to_consumerHomeFragment)
}
}
Tried navOptions but didn't worked
NavGraphCodes
app:startDestination="@id/selectLanguageFragment"
<fragment
android:id="@+id/selectLanguageFragment"
android:name="in.jadu.anjuconsumerapp.consumer.commonuis.SelectLanguageFragment"
android:label="Select Language" >
<action
android:id="@+id/action_selectLanguageFragment_to_phoneVerificationFragment"
app:destination="@id/phoneVerificationFragment" />
<action
android:id="@+id/action_selectLanguageFragment_to_consumerHomeFragment"
app:destination="@id/consumerHomeFragment"
app:popUpTo="@id/selectLanguageFragment"
app:popUpToInclusive="true" />
</fragment>
I have tried getSupportActionBar().setDisplayHomeAsUpEnabled(false)
but i didn't need this i just want to remove it from the navigation,
Upvotes: 0
Views: 122
Reputation: 729
So after struggling a lot watched a lot many yt videos, github I finally got the solution from androidx Docs Reference
So, When we are setting up the navigate up ...
Top Level Ids
will not have the back arrowcode
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navController = navHostFragment.navController
val appBarConfiguration = AppBarConfiguration(
topLevelDestinationIds = setOf(R.id.selectLanguage,R.id.farmerDashboard),
fallbackOnNavigateUpListener = ::onSupportNavigateUp
)
setupActionBarWithNavController(navController,appBarConfiguration)
Here i have declared both the fragments (selectLanguage,farmerDashboard) as top level so that i would not get the back button on these ids the rest app works fine ...
So , this was a simple thing
Hope this helps you :)
Upvotes: 1