I am working in Camera application, where if I change my permission manually from settings and came back to activity again, is giving me this error/crash.
You must call setGraph() before calling getGraph().
I am using activity/fragment from navigation library.
Navigation graph:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/guard_nav_graph"
app:startDestination="@id/cameraFragment">
<fragment
android:id="@+id/cameraFragment"
android:name="guard.camera.CameraFragment"
android:label="Camera"
tools:layout="@layout/fragment_guard_camera">
<action
android:id="@+id/action_cameraFragment_to_LocationFragment"
app:destination="@id/LocationFragment"
app:popEnterAnim="@anim/enter_from_left"
app:popExitAnim="@anim/exit_to_right">
<argument
android:name="isLocationAllowed"
app:argType="boolean" />
</action>
<argument
android:name="isEdit"
android:defaultValue="false"
app:argType="boolean" />
</fragment>
</navigation>
Gradle Library versions:
implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'
GuardActivity:
class GuardActivity : ActivityBase() {
private lateinit var binding: ActivityGuardBinding
private val navController: NavController by lazy {
findNavController(R.id.nav_host_fragment)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(R.style.AppTheme_NoActionBar)
binding = DataBindingUtil.setContentView(this, R.layout.guard)
setSupportActionBar(binding.incToolbar.toolBar)
NavigationUI.setupWithNavController(binding.incToolbar.toolBar, navController)
}
override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp() || super.onSupportNavigateUp()
}
}
XML file for activity:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".v2.guard.GuardActivity">
<include
android:id="@+id/inc_toolbar"
layout="@layout/fl_toolbar" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/inc_toolbar"
app:navGraph="@navigation/guard_nav_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>