bluelinelabs / Conductor

A small, yet full-featured framework that allows building View-based Android applications
Apache License 2.0
3.9k stars 343 forks source link

Android 12 new hardware back behavior for launcher Activities #659

Closed danilodanicomendes closed 2 years ago

danilodanicomendes commented 3 years ago

Hello,

There's a navigation issue in the demo app caused by the behavior change of the back button on Android 12.

Steps

  1. Open demo app
  2. Tap "Transition Demos"
  3. Tap hardware back twice (so you go back to device home launcher)
  4. Open demo app again
  5. Tap "Transition Demos"
  6. Tap hardware back once

Actual HomeController of the demo app is no longer shown when navigating back from TransitionDemoController. It just "moves" the app to background.

Expected Step 6. should result in navigating to the HomeController.

Why this happens?

Android 12 changes the default handling of the system Back press on launcher activities that are at the root of their tasks. In previous versions, the system would finish these activities on Back press. In Android 12, the system now moves the activity and its task to the background instead of finishing the activity. The new behavior matches the current behavior when navigating out of an app using the Home button or gesture. source: https://developer.android.com/about/versions/12/behavior-changes-all#back-press

The HomeController is set as root in the MainActivity.onCreate when it is popped on step 3. it is removed from the backstack. And step 4. only calls resume of the MainActivity meaning that the HomeController is not set as root again. Doing step 5. causes the TransitionDemoController to be pushed into the stack and at this point it's the only controller in the backstack.

I'm not fully satisfied with the solutions I came up so far. For that reason I wanted to ask:
How are you guys addressing this behavior change?

DavidBertet commented 2 years ago

I answered in #661, that might help you 👍

EricKuck commented 2 years ago

Version 3.1.3 of the app has a fix for this. Unfortunately this type of issue is impossible to fix automatically in the library, but it exposes a new Router.setPopRootControllerMode method that allows you to control what happens when it comes time to pop the final controller of a router. Options are: