https://kotlinlang.org logo
#compose
Title
# compose
r

Rick Regan

01/03/2022, 9:04 PM
In Android 12, swiping back from your app's home screen no longer "kills" the app. If the user wants to exit the app and start fresh, is the recommended way to do it to drag the app to Recents and then swipe it away? I was considering adding an "Exit" menu option to my app, which I have not seen in many apps, but which seems like a more direct way to restore the old back behavior. To implement that, what would be the right way in Compose? Specifically, I was wondering if it could be done with Navigation Compose.
b

Bradleycorn

01/03/2022, 9:19 PM
hmm … I don’t see any difference in behavior in my app between Android 11 and 12? In both, if I swipe back from the home screen, the app is placed into the “Recents” menu, and then if I click on the app again (either from Recents or clicking on the app icon), it loads my
SplashScreenActivity
and then loads the app’s
MainActivty
(where the home screen is rendered). It’s the same on both 11 and 12 (and 10 for that matter). In regards to an explicit way to “exit” … that’s not something for which there would be a “compose way” to do it. Compose is just a set of tools for rendering UI. You’ll also not find anything in the Navigation library to do it. You’ll have to handle it yourself by calling
finish()
on the Activity in response to some user interaction (say a button click on a menu item)
c

Colton Idle

01/03/2022, 9:52 PM
You're right in that hitting back on the root activity doesn't destroy that activity. I wouldn't add an exit button though. All of these things are just implementation details of the OS.
r

Rick Regan

01/03/2022, 10:15 PM
The behavior is documented here (which I found only after seeing it in my own app): https://developer.android.com/about/versions/12/behavior-changes-all#activity-lifecycle
I suppose you have to be using
savedInstanceState
(either directly, or through `rememberSaveable`~, like (presumably) Navigation Compose uses~ E_dit: not applicable since we are backing out of the root screen_) to notice it. You can check by printing
savedInstanceState
and seeing that it's not null on Android 12.
It's just interesting that if you're used to backing out of an app to "clear" it that that no longer works. I guess without an explicit exit option the user has to learn to swipe from Recents to do this.
c

Colton Idle

01/03/2022, 11:37 PM
Yeah. I doubt most users actually understood that there was a difference between back and home button.