I need to launch mViewMode.iniBilling(context as Activity)
first before I launch mViewMode.purchaseProduct(context as Activity)
in fun ScreenPurchase
.
You know the fun ScreenPurchase
may be launched repeatedly when the system needs to refresh UI.
I hope mViewMode.iniBilling(context as Activity)
can be launched only one time, how can I do?
@Composable
fun ScreenPurchase(
onBack: () -> Unit,
mViewMode: SoundViewModel,
scaffoldState: ScaffoldState = rememberScaffoldState()
) {
Scaffold(
modifier = Modifier.fillMaxSize(),
scaffoldState = scaffoldState,
topBar = { PurchaseAppBar(onBack = onBack) }
) { paddingValues ->
val context = LocalContext.current
mViewMode.iniBilling(context as Activity) //I hope it launched only one time.
Button(
modifier = Modifier,
onClick = {
mViewMode.purchaseProduct(context as Activity)
}
) {
Text(stringResource(R.string.btnBuy))
}
...
}
}