Skip to content

Commit 0a9f0f9

Browse files
committed
Do not change start destination on config change
1 parent c30bbad commit 0a9f0f9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

app/src/main/kotlin/com/w2sv/autocrop/MainActivity.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
2323

2424
if (BuildConfig.DEBUG) {
2525
findNavController(R.id.nav_host_fragment).apply {
26-
setStartDestinationBasedOnStartWithCropScreen()
26+
if (savedInstanceState == null && BuildConfig.START_WITH_CROP_SCREEN) {
27+
inflateGraphWithStartDestination(R.id.crop_nav_graph)
28+
}
2729
setupBackStackLogging(lifecycleScope)
2830
}
2931
}
@@ -40,12 +42,8 @@ private fun NavController.setupBackStackLogging(scope: CoroutineScope) {
4042
}
4143
}
4244

43-
private fun NavController.setStartDestinationBasedOnStartWithCropScreen() {
44-
@Suppress("KotlinConstantConditions")
45-
if (BuildConfig.START_WITH_CROP_SCREEN) {
46-
val graph = navInflater.inflate(R.navigation.nav_graph).apply {
47-
setStartDestination(R.id.crop_nav_graph)
48-
}
49-
this.graph = graph
45+
private fun NavController.inflateGraphWithStartDestination(destinationId: Int) {
46+
graph = navInflater.inflate(R.navigation.nav_graph).apply {
47+
setStartDestination(destinationId)
5048
}
5149
}

0 commit comments

Comments
 (0)