I have two LaunchedEffect scopes like this :
LaunchedEffect(key1 = mainViewModel.myvlue.value){ mainViewModel.updatemyvalue(1f) } LaunchedEffect(key1 = mainViewModel.myvlue.value){ mainViewModel.updatemyvalue(0f) } Both are implemented inside this method :
@Composable fun TabContent( pagerState: PagerState,count:Int,mainViewModel: MainViewModel) { HorizontalPager(state = pagerState, count = count) { index -> when (index) { 0 -> { LaunchedEffect(key1 = mainViewModel.myvlue.value){ mainViewModel.updatemyvalue(1f) } SecondScreen(mainViewModel) } 1 -> { LaunchedEffect(key1 = mainViewModel.myvalue.value) { mainViewModel.updatemyvalue(0f) } firstScreen(mainViewModel) } } } } The problem is that when one of these scopes launches, second one will be automatically called .
I know this is normal that when the key1 value changes scopes will be relaunched . but I just want them to be called separately when I navigate to their respective page inside HorizontalPager.
As you can see above, they will be called simultaneously when one of the executes.
what should I do ?