Skip to content

fix: restore in-app back navigation under predictive back - #628

Merged
fortuna merged 1 commit into
masterfrom
fix/predictive-back
Sep 15, 2026
Merged

fortuna merged 1 commit into
masterfrom
fix/predictive-back

Conversation

@fortuna

@fortuna fortuna commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes in-app back navigation, which is broken on master right now, and resolves the
GestureBackNavigation lint error.

Important

This is a follow-up to #623 (already merged). That PR bumped targetSdk to 36, which is
what introduced this regression. This PR is based directly on master and is
independent of the AGP stack (#625/#626/#627), so it can merge on its own.

The bug

MainActivity overrode onBackPressed() so that back returns to the home view from the
settings and info screens:

  @Override
  public void onBackPressed() {
    if (isShowingHomeView()) {
      super.onBackPressed();
      return;
    }
    chooseView(R.id.frame_main);
  }

Apps targeting SDK 36 can no longer opt out of predictive back, and the platform
routes back gestures through OnBackPressedDispatcher instead of calling
onBackPressed(). So pressing back from Settings exits the app rather than returning
to the home view.

This is specific to targetSdk 36 — it is not a pre-existing bug. Running lintDebug
across targetSdk values on an otherwise identical tree:

targetSdk total lint errors GestureBackNavigation
33 3 not reported
34 4 not reported
35 4 not reported
36 5 reported

targetSdk 35 (Android 15) turned on predictive back animations but kept the legacy
onBackPressed() path working. targetSdk 36 (Android 16) removes that compatibility path.

The fix

Register an OnBackPressedCallback on the dispatcher instead, enabled only while a
non-home view is showing:

  private final OnBackPressedCallback backToHomeCallback = new OnBackPressedCallback(false) {
    @Override
    public void handleOnBackPressed() {
      chooseView(R.id.frame_main);
    }
  };

chooseView() is the single funnel for every view change, so it is the natural place to
keep the enabled state in sync. It sits right next to the existing up-arrow logic, which
already encodes the same "am I on the home view" condition:

    backToHomeCallback.setEnabled(id != R.id.frame_main);

When disabled, back falls through to the system and leaves the app, preserving the
original behavior. isShowingHomeView() has no remaining callers and is removed.

Why AppCompat moves 1.4.0 -> 1.7.1

Bridging the platform's OnBackInvokedCallback into OnBackPressedDispatcher needs
androidx.activity 1.6+. The pinned appcompat 1.4.0 resolved activity:1.2.4, which
predates predictive back entirely. appcompat 1.7.1 pulls activity:1.8.0.

Note

appcompat 1.8.0 is newer, but requires raising minSdk to 23:

uses-sdk:minSdkVersion 21 cannot be smaller than version 23 declared in library
[androidx.appcompat:appcompat-resources:1.8.0]

1.7.1 is used deliberately so that minSdk stays at 21 and Android 5.x users are not
dropped. For a censorship-circumvention tool, old devices are worth keeping.

gradle/verification-metadata.xml is updated with the new transitive dependencies
(activity 1.8.0, lifecycle 2.6.x, core 1.13.0, emoji2, savedstate, profileinstaller, ...).

Verification

  • ./gradlew clean assembleDebug test passes.
  • GestureBackNavigation is gone. The remaining lint errors are the 3 pre-existing ones
    (StartActivityAndCollapseDeprecated, RestrictedApi, QueryAllPackagesPermission).

Exercised on a Pixel 8 emulator running API 36 (the configuration where the bug
reproduces), driving the UI over adb + uiautomator:

Check Result
Drawer -> Settings shows the settings view pass
Back from Settings stays in the app pass
Back from Settings returns to the home view pass
Tapping a stat box shows the info view pass
Back from the info page stays in the app pass
Back from the info page returns to the home view pass
Back from the home view leaves the app pass
No crashes in logcat pass

Both chooseView() entry points are covered: the settings view and the info view. Back
from the home view still exits, so the pre-existing behavior is preserved.

@fortuna
fortuna added this pull request to stack #624 September 15, 2026 18:06
@peterwgnd
peterwgnd force-pushed the build/remove-legacy-agp-flags branch from b05742a to dca8589 Compare September 15, 2026 18:17
@fortuna
fortuna removed this pull request from stack #624 September 15, 2026 18:21
@fortuna
fortuna force-pushed the fix/predictive-back branch from 1d9054e to fdeed0f Compare September 15, 2026 18:22
@fortuna
fortuna changed the base branch from build/remove-legacy-agp-flags to master September 15, 2026 18:22
@fortuna
fortuna requested a review from peterwgnd September 15, 2026 18:35
@fortuna
fortuna force-pushed the fix/predictive-back branch from fdeed0f to d802521 Compare September 15, 2026 18:41
MainActivity overrode onBackPressed() to return to the home view from the
settings and info screens. Apps targeting SDK 36 can no longer opt out of
predictive back, and the platform now routes back gestures through
OnBackPressedDispatcher instead of calling onBackPressed(), so back was
leaving the app instead of returning home. Lint flags this as
GestureBackNavigation, and only at targetSdk 36 -- the bump in #623 is what
introduced the regression.

Replace the override with an OnBackPressedCallback registered on the
dispatcher. The callback is enabled only while a non-home view is showing,
mirroring the existing up-arrow logic in chooseView(), so back still exits
the app from the home view. isShowingHomeView() is now unused and removed.

This needs androidx.activity 1.6+ to bridge the platform callback; the
pinned appcompat 1.4.0 only brings in activity 1.2.4. Upgrade appcompat to
1.7.1, which pulls activity 1.8.0 and still supports minSdk 21. Deliberately
not 1.8.0, which would require raising minSdk to 23.
@fortuna
fortuna force-pushed the fix/predictive-back branch from d802521 to bd66ebc Compare September 15, 2026 18:43
@fortuna
fortuna requested a review from jyyi1 September 15, 2026 18:45

@jyyi1 jyyi1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@fortuna
fortuna merged commit ebee745 into master Sep 15, 2026
12 checks passed
@fortuna
fortuna deleted the fix/predictive-back branch September 15, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants