I using paging with Compose but it crashes the app...
# compose
s
I using paging with Compose but it crashes the app on orientation change, but with the normal list, it's work fine.
Copy code
--------------------- in ViewModel ---------------------------- 
val newsSelection : MutableStateFlow<HeadlinesPagingKey> = MutableStateFlow(
            HeadlinesPagingKey())

@ExperimentalCoroutinesApi
     val topHeadlines: Flow<PagingData<Article>> =
             newsSelection.flatMapLatest {
                 newsRepository.topNewsHeadlines(it)
             }.shareIn(viewModelScope, SharingStarted.Lazily,1)

---------------------and in Composable---------------------------- 

val lazyPagingItems: LazyPagingItems<Article> =
        headlinesViewModel.topHeadlines.collectAsLazyPagingItems()
a
could you share a crash?
s
I am getting this exception when using shareIn operator java.lang.IllegalStateException: Attempt to collect twice from pageEventFlow, which is an illegal operation. Did you forget to call Flow<PagingData<*>>.cachedIn(coroutineScope)?