From f3107e349c564598ca8a4b3eaaf48fa92a7ec367 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 23 Mar 2023 15:01:09 +0100 Subject: ui: switch from using launchWhenCreated to using repeatOnLifecycle Apparently the former is deprecated. Signed-off-by: Jason A. Donenfeld --- ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3