Status Update
Comments
da...@gmail.com <da...@gmail.com> #2
Is this specific to navigation? Or can this be reproduced with another other Composable component?
wu...@google.com <wu...@google.com> #3
It only happens inside of a NavHost. So, yes, it seems to be specific to navigation.
sc...@google.com <sc...@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
.
sh...@google.com <sh...@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
da...@gmail.com <da...@gmail.com> #6
This has been fixed internally and will be available in Navigation 2.7.0-beta01.
da...@gmail.com <da...@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
sc...@google.com <sc...@google.com> #8
tr...@google.com <tr...@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
}
}
sc...@google.com <sc...@google.com> #10
mi...@google.com <mi...@google.com> #11
ap...@google.com <ap...@google.com> #12
Bug Fixes : NavHost in Navigation Compose now correctly intercepts system back calls even after the Activity has been STOPPED and RESUMED.
It works fine for me.
mi...@google.com <mi...@google.com> #13
da...@gmail.com <da...@gmail.com> #14
In my case it works fine when the app is first ran, but my custom callback calls navController.popBackStack internally if it can't handle back press on its own. So, when I run the app and click back, everything works, but after I pop up all the Composables from the stack and return to the app, the custom callback is not called anymore.
mi...@google.com <mi...@google.com> #15
Re
Note that you should never, ever be calling navController.popBackStack()
in your own BackHandler
as Navigation must be the only one handling its own back stack with the system back button so that Predictive Back works correctly in the future.
Description
We're receiving these crash reports for our app on the Play Store (https://play.google.com/store/apps/details?id=app.grapheneos.camera.play ). I'm unsure why it's happening, but perhaps you can get one of these devices and reproduce it. Ideally, CameraX could at least start catching this exception and turning it into an error surfaced to the app.
We're mostly seeing these crashes from the Jio JioPhone Next which is a very widely used, very cheap device in India. The crash traceback is nearly identical across the around 5 device models where we've seen it with only minor variations in Camera2 implementation line numbers. All of the impacted devices are Android 11.