summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2023-03-23 15:01:09 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2023-03-23 15:01:09 +0100
commitf1cb4c2164f03d126cc67714b580696e24fca9ed (patch)
treebc3358ecc6d3e3fd7f3ec26461acad2c9454e8f2
parentbe9695a0c101e2e582bea9535be3c94ea43a0c6c (diff)
ui: switch from using launchWhenCreated to using repeatOnLifecycle
Apparently the former is deprecated. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt9
1 files changed, 8 insertions, 1 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 6c85be57..204a5a80 100644
--- a/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt
+++ b/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt
@@ -7,9 +7,12 @@ package com.wireguard.android.activity
import android.os.Bundle
import androidx.databinding.CallbackRegistry
import androidx.databinding.CallbackRegistry.NotifierCallback
+import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
+import androidx.lifecycle.repeatOnLifecycle
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.
@@ -37,7 +40,11 @@ abstract class BaseActivity : ThemeChangeAwareActivity() {
else -> null
}
if (savedTunnelName != null)
- lifecycleScope.launchWhenCreated { selectedTunnel = Application.getTunnelManager().getTunnels()[savedTunnelName] }
+ lifecycleScope.launch {
+ repeatOnLifecycle(Lifecycle.State.CREATED) {
+ selectedTunnel = Application.getTunnelManager().getTunnels()[savedTunnelName]
+ }
+ }
// The selected tunnel must be set before the superclass method recreates fragments.
super.onCreate(savedInstanceState)