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-24 14:12:21 +0100
commitf3107e349c564598ca8a4b3eaaf48fa92a7ec367 (patch)
tree9f681711bcc50aac3e10ff6c100fe27aee268c33
parentcaf2cded6edf087c55bce873e649388daf234724 (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)