react / react/react-native

bug: back handler stops working after re-foregrounding the app

Ouverte
#54,887 7 commentaires 3 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Needs: Triage :mag:
Langage dominant
C++
Étoiles
127k
Forks
25.3k
Merge moyen
1 j 23 h
PR mergées (30 j)
4

Description

Description

back handlers seem to stop working after sending the app to the background - all back gestures (except in Modals) just close the app instead. see the video below for a clearer demonstration.

I'm using the Android 16 QPR2 beta (BP41.250916.015.A1) on a Pixel 8.

I can reproduce this using either the @react-native-community/hooks hook or the usage example in the BackHandler docs. the hook works fine in React Native v0.80 (I assume because the target SDK was still 35?).

Steps to reproduce
  1. Start the app
  2. Press the button at the top
  3. Do a back gesture and observe that it respects the back handler
  4. Do another one to go home
  5. Re-open the app
  6. Press the button at the top again
  7. Do another back gesture and observe that it exits out of the app instead of respecting the back handler
React Native Version

0.83.0

Affected Platforms

Runtime - Android, Build - Linux

Output of npx @react-native-community/cli info
System:
  OS: Linux 6.17 Ubuntu 25.10 25.10 (Questing Quokka)
  CPU: (8) x64 Intel(R) Core(TM) Ultra 7 256V
  Memory: 4.46 GB / 14.72 GB
  Shell:
    version: 5.2.37
    path: /bin/bash
Binaries:
  Node:
    version: 24.5.0
    path: /home/rexo/.nvm/versions/node/v24.5.0/bin/node
  Yarn:
    version: 4.12.0
    path: /home/rexo/.nvm/versions/node/v24.5.0/bin/yarn
  npm:
    version: 11.5.1
    path: /home/rexo/.nvm/versions/node/v24.5.0/bin/npm
  Watchman: Not Found
SDKs:
  Android SDK:
    API Levels:
      - "31"
      - "35"
      - "36"
    Build Tools:
      - 34.0.0
      - 35.0.0
      - 35.0.1
      - 36.0.0
    System Images:
      - android-35 | Google APIs Intel x86_64 Atom
      - android-35 | Google Play Intel x86_64 Atom
      - android-36 | Google Play Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: Not Found
Languages:
  Java:
    version: 17.0.17
    path: /usr/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.2.0
    wanted: 19.2.0
  react-native:
    installed: 0.83.0
    wanted: 0.83.0
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false
Stacktrace or Logs
N/A
MANDATORY Reproducer

https://github.com/Rexogamer/backhandler-test

Screenshots and Videos

https://github.com/user-attachments/assets/a48256a0-d956-446d-b5da-1ceccc824d91

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le reproducer obligatoire et l’exemple d’utilisation de BackHandler liés dans l’issue, en les exécutant sur Android 16 QPR2 avec React Native 0.83. Comparez le comportement du back-handler avant la mise en arrière-plan et après la réouverture de l’application. Le travail est terminé lorsque les handlers enregistrés continuent de s’exécuter après le retour de l’application au premier plan, au lieu que le geste de retour quitte l’application.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
react-native
Domaine
mobile
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
48/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.