:question: Where can i find that sample? :thinking...
# compose
t
Where can i find that sample? 🤔 I’ve looked at cs.android.com
Copy code
* @sample androidx.activity.compose.samples.BackHandler
t
@Albert Chang Yeah, i’ve seen that one. but the sample is not using the
BackHandler
method.
i
Yes it is: line 34
t
Ohh okay. my bad 🤦‍♂️
but i was looking for an advanced example. especially the usage of
enabled
flag. for eg, how do i turn off the
BackHandler
and pass the backpress event to system.
another eg would, when the
navController
doesn’t have anything to pop and i need to close the activity. can i simply hoist a callback and call
finish()
on activity ?
r
i
If the
NavController
has no destination to pop, it will automatically set its own back handler to disabled, you don't have to do anything to get the default behavior to finish your activity when there's nothing to pop
t
Okay. now i got it. the problem was I didn’t disable the BackHandler. so it was intercepting the back press call. @Ian Lake what’s the recommended way to close the activity if there’s only one entry remaining? (current problem is, once all destinations are popped, the app shows a blank screen, then only it closes the activity)
i
That's not how NavController works - it only enables it's back handler if there are more than one destination on the back stack. If there's only one left, it will be disabled and the activity will be finished. Note that there was a bug fix for this when using dialog destination that was fixed in alpha06
File a bug if you're still seeing it in alpha06