Skip to content

Commit 763d9a9

Browse files
committed
ui: set selected tunnel after creating fragments
I'm not sure why that comment (Samuel's) was there saying it was necessary. Given it's been async for a long while, this wasn't guaranteed anyway. So let's get rid of it and see what happens. Screen rotation seems fine thus far. Cc: Samuel Holland <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent f3107e3 commit 763d9a9

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ package com.wireguard.android.activity
77
import android.os.Bundle
88
import androidx.databinding.CallbackRegistry
99
import androidx.databinding.CallbackRegistry.NotifierCallback
10-
import androidx.lifecycle.Lifecycle
1110
import androidx.lifecycle.lifecycleScope
12-
import androidx.lifecycle.repeatOnLifecycle
1311
import com.wireguard.android.Application
1412
import com.wireguard.android.model.ObservableTunnel
1513
import kotlinx.coroutines.launch
@@ -33,6 +31,8 @@ abstract class BaseActivity : ThemeChangeAwareActivity() {
3331
}
3432

3533
override fun onCreate(savedInstanceState: Bundle?) {
34+
super.onCreate(savedInstanceState)
35+
3636
// Restore the saved tunnel if there is one; otherwise grab it from the arguments.
3737
val savedTunnelName = when {
3838
savedInstanceState != null -> savedInstanceState.getString(KEY_SELECTED_TUNNEL)
@@ -41,13 +41,8 @@ abstract class BaseActivity : ThemeChangeAwareActivity() {
4141
}
4242
if (savedTunnelName != null)
4343
lifecycleScope.launch {
44-
repeatOnLifecycle(Lifecycle.State.CREATED) {
45-
selectedTunnel = Application.getTunnelManager().getTunnels()[savedTunnelName]
46-
}
44+
selectedTunnel = Application.getTunnelManager().getTunnels()[savedTunnelName]
4745
}
48-
49-
// The selected tunnel must be set before the superclass method recreates fragments.
50-
super.onCreate(savedInstanceState)
5146
}
5247

5348
override fun onSaveInstanceState(outState: Bundle) {

0 commit comments

Comments
 (0)