Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android "back" quits the app completely #638

Open
gnprice opened this issue Apr 30, 2024 · 2 comments
Open

Android "back" quits the app completely #638

gnprice opened this issue Apr 30, 2024 · 2 comments
Labels
a-Android Issues specific to Android, or requiring Android-specific work a-home The home screens of the app; finding and starting conversations upstream Would benefit from work in Flutter or another upstream

Comments

@gnprice
Copy link
Member

gnprice commented Apr 30, 2024

Repro steps:

  • On Android, launch the app. Wait for data to load.
  • Swipe back several times, until you're back at the system home screen.
  • Launch the app again.
  • Actual: The app has to load the data again from scratch.
  • Expected: The app was still running in the background, so that the data is all ready.

This is an upstream Flutter issue:

The expected behavior is new in Android 12 (so in 2021); before that, our actual behavior was expected. See Android docs:
https://developer.android.com/about/versions/12/behavior-changes-all#back-press

I don't think there's a particularly straightforward workaround for us within the app, but hopefully it'll get fixed upstream. (So filing this issue mainly to track that this is a known issue and what the root cause is, in case people notice it again in the future.) Here's my summary of the state of the issue: flutter/flutter#117061 (comment)

@gnprice gnprice added a-Android Issues specific to Android, or requiring Android-specific work a-home The home screens of the app; finding and starting conversations labels Apr 30, 2024
@gnprice gnprice added this to the Post-launch milestone Apr 30, 2024
@simon-the-shark
Copy link

Hello, have you tried this: flutter/flutter#117061 (comment)?

@gnprice
Copy link
Member Author

gnprice commented May 24, 2024

Interesting, thanks @simon-the-shark!

I'd encourage you to try fixing this bug in Flutter upstream. That would be especially valuable because it means that everyone using Flutter would get the benefit of your fix.

Another benefit of an upstream fix is that I think it can ultimately be a lot less code. Fundamentally Flutter already has a sensible system for delegating from one piece of code to another the decision of what should happen on a back gesture: falling back from individual routes with custom logic, to the navigator's generic logic, to platform logic for when at the root of the navigation. The trouble is just that at the very end of that fallback chain, it makes the wrong decision (wrong since Android 12), at this line of code:

  private void popSystemNavigator() {
    // …
      activity.finish();

So by fixing that line to instead call Activity#onBackPressed, it becomes unnecessary to intercept Flutter's normal flow for deciding what to do with a back gesture, or to introduce a new MethodChannel.

If you do send a PR upstream, please feel free to ping me there and/or on this thread, and I'd be glad to do a review (I'm a Flutter committer). For questions leading up to a PR, you may find the Flutter contributor Discord helpful; try #hackers or #hackers-android, and feel free to ping me in a channel on that Discord too.

@gnprice gnprice added the upstream Would benefit from work in Flutter or another upstream label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-Android Issues specific to Android, or requiring Android-specific work a-home The home screens of the app; finding and starting conversations upstream Would benefit from work in Flutter or another upstream
Projects
Status: No status
Development

No branches or pull requests

2 participants