Status Update
Comments
yb...@google.com <yb...@google.com> #2
Is this specific to navigation? Or can this be reproduced with another other Composable component?
ge...@gmail.com <ge...@gmail.com> #3
It only happens inside of a NavHost. So, yes, it seems to be specific to navigation.
yb...@google.com <yb...@google.com>
cc...@google.com <cc...@google.com> #4
This was caused by the fix to BackHandler
lifecycle aware. The problem here is that the NavController
registers its lifecycle and added an observer to the Activity
Lifecycle
in composition while the BackHandler
registers its observer on the Activity
Lifecycle
in a DisposbleEffect
. This means that the NavController
will always get Lifecycle callbacks before the BackHandler
, so the components listening the the NavController
's lifecycle (like the NavBackStackEntry) will always get their Lifecycle callbacks before the BackHandler
as well.
This should be addressed by work coming in 2.7 to integrate the BackHandler
into the NavHost
.
cc...@google.com <cc...@google.com> #5
Branch: androidx-main
commit d2c5efe67531a30fb9f1a129d52beb1e9ece0b29
Author: Jeremy Woods <jbwoods@google.com>
Date: Wed May 31 23:09:54 2023
Integrate BackHandler into NavHost
Instead of NavHost taking over the onBackPressedDispatcher from the
Activity, we should just make it use a BackHandler. This will ensure
that it interacters with the other BackHandlers in Compose correctly.
RelNote: "`NavHost` now correctly intercepts system back calls even
after the Activity has been `STOPPED` and `RESUMED`."
Test: modified tests
Bug: 279118447
Change-Id: Icb6deab996d122487243f0d3d775af8c15fc7c25
M navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostTest.kt
M navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHost.kt
ge...@gmail.com <ge...@gmail.com> #6
This has been fixed internally and will be available in Navigation 2.7.0-beta01.
ge...@gmail.com <ge...@gmail.com> #7
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-compose:2.7.0-beta01
yb...@google.com <yb...@google.com> #8
cc...@google.com <cc...@google.com> #9
I wouldn't say this is fixed. If you add a back-callback in the activity which is lifecycle aware, and then background->foreground the app, the activity back-callback will be put on top of the callback pile. This leads to that any BackHandler in your composable will NOT be triggered.
The best workaround I have for now is to use the non-lifecycle aware function in the activity.
class MainActivity : FragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// open fragment which hoists the composables
...
if (savedInstanceState == null) {
onBackPressedDispatcher.addCallback(onBackPressedCallback = someBackHandling())
// onBackPressedDispatcher.addCallback(owner = this, onBackPressedCallback = someBackHandling) // not this one
}
}
Description
Version used: AndroidX 1.0.0-rc02, Paging:2.0.0-rc01
I use Room to load from database and display in Recyclerview using Paging library. The list will crash randomly if I scroll the list up and down very fast. Not every time but I can reproduce it easily, especially if the list is large.
Below is the crash stack:
java.lang.IndexOutOfBoundsException: Index out of bounds - passed position = 447, old list size = 240
at androidx.recyclerview.widget.DiffUtil$DiffResult.convertOldPositionToNew(DiffUtil.java:672)
at androidx.paging.PagedStorageDiffHelper.transformAnchorIndex(PagedStorageDiffHelper.java:196)
at androidx.paging.AsyncPagedListDiffer.latchPagedList(AsyncPagedListDiffer.java:343)
at androidx.paging.AsyncPagedListDiffer$2$1.run(AsyncPagedListDiffer.java:312)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)