Skip to content

Register the ReactActivity back callback on Android 13+ for apps targeting SDK 36 - #59897

Open
chocky335 wants to merge 1 commit into
react:mainfrom
chocky335:android/back-callback-api33
Open

chocky335 wants to merge 1 commit into
react:mainfrom
chocky335:android/back-callback-api33

Conversation

@chocky335

Copy link
Copy Markdown

Summary:

Fixes #58407. On Android 13 to 15, an app that sets android:enableOnBackInvokedCallback="true" receives Back through OnBackInvokedDispatcher, and ReactActivity registers its OnBackPressedCallback only when the device also runs API 36, so BackHandler never sees the press and Back closes the app. ReactActivity.onCreate now registers the callback on API 33+ when the app targets SDK 36, the condition #51096 describes.

Review focus: apps that target SDK 35 or lower and opt in are still not covered, because Android has no public API to read the opt-in. Dropping the targetSdkVersion condition would register the callback on every API 33+ device. Without the opt-in, Android keeps sending Back to onBackPressed() there, so the callback would stay unused.

Changelog:

[ANDROID] [FIXED] - Fix BackHandler not receiving hardwareBackPress on Android 13 to 15 when the app targets SDK 36 and sets android:enableOnBackInvokedCallback="true"

Test Plan:

  • New Robolectric test ReactActivityBackCallbackTest at sdk 33, 34 and 35. On main the 6 targetSdk 36 cases fail: no callback is registered and a back press never reaches ReactActivityDelegate.onBackPressed(). With this change all 8 cases pass. Robolectric 4.15 on JDK 17 has no sdk 36, so API 36+ was checked on a device.
    ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests com.facebook.react.ReactActivityBackCallbackTest
    
  • Full :packages:react-native:ReactAndroid:testDebugUnitTest: 903 tests, 0 failures. yarn format-check-java and yarn format-check-kotlin pass.
  • Reporter's repro (https://github.com/DanyKrk/android-backhandler-api35-repro, RN 0.87.1, targetSdk 36, opt-in on), release builds. The "after" build compiles React Native from source with this patch:
    • Xiaomi Mi 11 Lite, Android 13 (API 33): before, Back sends the app to the home screen and hardwareBackPress received is never logged. After, each of 3 presses logs it, the counter shows 3 and the app stays open.
    • Pixel 8 Pro, Android 17 (API 37): before and after, each press reaches JS.

@meta-cla

meta-cla Bot commented Nov 9, 2026

Copy link
Copy Markdown

Hi @chocky335!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 9, 2026
@meta-cla

meta-cla Bot commented Nov 9, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] BackHandler receives no events on API 35 with predictive Back enabled

1 participant