[#450] Solve multiple calls to Play Core with LaunchedEffect

This commit is contained in:
Honza Rychnovsky 2022-06-08 10:39:33 +02:00 committed by GitHub
parent 0dfd8d1e22
commit b4bad94068
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import androidx.annotation.VisibleForTesting
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
@ -386,8 +387,6 @@ class MainActivity : ComponentActivity() {
@Composable
private fun WrapCheckForUpdate() {
// and then check for an app update asynchronously
checkUpdateViewModel.checkForAppUpdate()
val updateInfo = checkUpdateViewModel.updateInfo.collectAsState().value
updateInfo?.let {
@ -395,6 +394,12 @@ class MainActivity : ComponentActivity() {
WrapUpdate(updateInfo)
}
}
// Check for an app update asynchronously. We create an effect that matches the activity
// lifecycle. If the wrapping compose recomposes, the check shouldn't run again.
LaunchedEffect(true) {
checkUpdateViewModel.checkForAppUpdate()
}
}
@Composable