diff options
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt b/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt index bdf0f8d4..8f0855ea 100644 --- a/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2017-2021 WireGuard LLC. All Rights Reserved. + * Copyright © 2017-2023 WireGuard LLC. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ package com.wireguard.android.activity @@ -10,6 +10,7 @@ import androidx.databinding.CallbackRegistry.NotifierCallback import androidx.lifecycle.lifecycleScope import com.wireguard.android.Application import com.wireguard.android.model.ObservableTunnel +import kotlinx.coroutines.launch /** * Base class for activities that need to remember the currently-selected tunnel. @@ -30,6 +31,8 @@ abstract class BaseActivity : ThemeChangeAwareActivity() { } override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + // Restore the saved tunnel if there is one; otherwise grab it from the arguments. val savedTunnelName = when { savedInstanceState != null -> savedInstanceState.getString(KEY_SELECTED_TUNNEL) @@ -37,10 +40,9 @@ abstract class BaseActivity : ThemeChangeAwareActivity() { else -> null } if (savedTunnelName != null) - lifecycleScope.launchWhenCreated { selectedTunnel = Application.getTunnelManager().getTunnels()[savedTunnelName] } - - // The selected tunnel must be set before the superclass method recreates fragments. - super.onCreate(savedInstanceState) + lifecycleScope.launch { + selectedTunnel = Application.getTunnelManager().getTunnels()[savedTunnelName] + } } override fun onSaveInstanceState(outState: Bundle) { |