I am displaying a paginated list using paging library in a lazy column in a bottom nav bar with 4 tabs say HomeScreen. When its item is clicked it will to next activity with normal intent . But when i press back key and come back to the composable which has the paginated list . it starts recomposing and the list is shown from the first. How to retain the state of the composable when coming back from other activity on stack. Only when clicking on a paginated list item and navigating and press back key to revisit HomeScreen the composable with paging list is recomposing and the list is show from first, other tabs with noraml lazy list is working perfectly on back key revisit. Please help maintain the list state when revisiting the screen when come to Home screen back from Details page
// getting paged data inside composable
val pagedList = viewModel.getPagedList().collectAsLazyPagingItems()
//navigating on click item
val context = LocalContext.current
context.openActivity(
DetailsScreen::class.java,
extras = {
putInt("id", 5)
})
//open activity extension
fun <T> Context.openActivity(
it: Class<T>,
shouldFinish: Boolean = false,
extras: Bundle.() -> Unit = {},
isOutsideActivity: Boolean = false
) {
val intent = Intent(this, it)
if (isOutsideActivity) {
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
intent.putExtras(Bundle().apply(extras))
startActivity(intent)
if (shouldFinish)
this.findActivity()?.let {
it.finish()
}
}