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

The system back button closes the app on Android 13 #1538

Open
SametSahin10 opened this issue May 9, 2023 · 15 comments
Open

The system back button closes the app on Android 13 #1538

SametSahin10 opened this issue May 9, 2023 · 15 comments

Comments

@SametSahin10
Copy link
Contributor

The system back button closes the app on Android when it's supposed go back to the previous page. The issue does not occur on Android 10. It occurs on Android 13. I have run my app on an Android 10 device and pressed the system back button. The didPopRoute on RootBackButtonDispatcher has been called. I've run the app on my Android 13 device and pressed the system back button but the didPopRoute hasn't been called. What could be the issue here?

I'm using:

auto_route: ^7.1.0
auto_route_generator: ^7.0.0

flutter doctor -v

[✓] Flutter (Channel stable, 3.7.12, on macOS 13.3.1 22E772610a darwin-arm64, locale en-TR)
    • Flutter version 3.7.12 on channel stable at /Users/sametsahin/work/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4d9e56e694 (3 weeks ago), 2023-04-17 21:47:46 -0400
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/sametsahin/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.78.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.62.0

[✓] Connected device (3 available)
    • SM G960U1 (mobile) • 395a545443503098 • android-arm64  • Android 10 (API 29)
    • macOS (desktop)    • macos            • darwin-arm64   • macOS 13.3.1 22E772610a darwin-arm64
    • Chrome (web)       • chrome           • web-javascript • Google Chrome 112.0.5615.137

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
@AlexandrMolecule
Copy link

@SametSahin10
Copy link
Contributor Author

Users who are having this issue, what's the value of android:launchMode in your AndroidManifext.xml? If it's singleTask, try changing it to singleTop and check if the issue gets resolved.

@SametSahin10
Copy link
Contributor Author

Are you having the issue? @AlexandrMolecule Can you try my suggestion above?

@Milad-Akarie
Copy link
Owner

Hey @SametSahin10 is this documented somewhere or did you just tried it your self?

@SametSahin10
Copy link
Contributor Author

My coworker made some changes in AndroidManifest.xml and the issue got resolved. I'm trying to isolate the change that fixed the issue.

@zatovagul
Copy link

Have the same problem, but launchMode is singleTop

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

@vaspadi
Copy link

vaspadi commented Aug 17, 2023

I have the same issue: pressing the hardware back button closes the application, and I can't intercept this behavior (Android 13.1; android:launchMode="singleTop" in AndroidManifest.xml; auto_route v6.4.0). I tried working with RootBackButtonDispatcher and AutoRouterDelegate, but debug breakpoints didn't even stop in them. Maybe I did it in the wrong place?

I tried to intercept the event here:

Widget build(BuildContext context) {
  final router = ref.watch(routerProvider).rootRouter;
  
   MaterialApp.router(
      debugShowCheckedModeBanner: false,
      routerConfig: router.config(),
      // routerConfig: RouterConfig(
      //   routeInformationProvider: router.routeInfoProvider(),
      //   routeInformationParser: router.defaultRouteParser(),
      //   routerDelegate: router.delegate(),
      // ),
   );
}

Here is how my app_router.dart looks. MainRoute is a TabsRouter.

@AutoRouterConfig(replaceInRouteName: 'View|RouterView,Route')
class AppRouter extends _$AppRouter {
  @override
  final List<AutoRoute> routes = [
    AutoRoute(
      path: '/first-page',
      page: FirstRoute.page,
      initial: !EnvConfig.mainRouteInPriority,
      guards: [LogoutGuard()],
    ),
    AutoRoute(
      path: '/local-auth',
      page: LocalAuthRoute.page,
      guards: [AuthGuard()],
      initial: EnvConfig.mainRouteInPriority,
    ),
    AutoRoute(
      path: '/main',
      page: MainRoute.page,
      guards: [AuthGuard(), PushNotificationsGuard()],
      children: [
        RedirectRoute(
          path: '',
          redirectTo: 'home',
        ),
        AutoRoute(
          path: 'home',
          page: HomeRouter.page,
          children: [
            AutoRoute(path: '', page: HomeRoute.page),
          ],
        ),
        AutoRoute(
          path: 'support',
          page: SupportRouter.page,
          children: [
            AutoRoute(
              path: '',
              page: SupportRoute.page,
            ),
            AutoRoute(
              path: 'ticket-creating-first-step',
              page: TicketCreatingFirstStepRoute.page,
            ),
            AutoRoute(
              path: 'ticket-creating-second-step',
              page: TicketCreatingSecondStepRoute.page,
            ),
            AutoRoute(
              path: 'chat',
              page: SupportChatRoute.page,
            ),
          ],
        ),
      ],
    ),
  ];
}

Main page with tabs:

Widget build(BuildContext context, ref) {
  return AutoTabsScaffold(
    routes: TabData.values.map((e) => e.route).toList(),
    bottomNavigationBuilder: (_, tabsRouter) {
      return BottomAppBar(...);
      },
  );
}

RouterView for the support tab:

@RoutePage(name: 'SupportRouter')
class SupportRouterView extends ConsumerWidget {
  const SupportRouterView({super.key});

  @override
  Widget build(BuildContext context, ref) {
    final routerKeys = ref.watch(routerProvider).tabRouterKeys;

    return AutoRouter(
      key: routerKeys[TabData.support],
    );
  }
}

@NachiketaVadera
Copy link

Facing the same issue on Android 13. Could it be related to this?
https://developer.android.com/about/versions/12/behavior-changes-all#back-press

@Kuzmenko
Copy link

Kuzmenko commented Sep 1, 2023

It looks like cause of issue is the https://developer.android.com/guide/navigation/custom-back/predictive-back-gesture, you can find related discussion here flutter/flutter#109513.
As a temporary solution, I've removed
android:enableOnBackInvokedCallback="true" from manifest

@github-actions
Copy link

github-actions bot commented Oct 6, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

@rignaneseleo
Copy link

rignaneseleo commented Nov 9, 2023

Same problem on Android 14, reported in detail on #1788

EDIT: the problem is gone using @Kuzmenko solution

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

@ciriousjoker
Copy link

I have the same issue, but in my case the issue goes away when extending FlutterActivity instead of FlutterFragmentActivity.

Does this have anything to do with this issue?

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants