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

Tapping on push notification restarts backgrounded app on Android #414

Open
karim-cardeo opened this issue Mar 7, 2024 · 14 comments
Open
Labels
platform-android Specific to Android platform support Asking for help writing an application

Comments

@karim-cardeo
Copy link

Hi folks,

I have recently found an issue which occurs when tapping on a push notification sent by Intercom on Android if the app is in the background.

Steps to replicate:

Given I have an Android Flutter app with the intercom_flutter package installed and correctly setup,
And I have launched the app and put it in the background,
When I receive a push notification from Intercom,
And I tap on the push notification,
Then I am routed to the Intercom messenger,
And the app is restarted.

The expected result should instead be that the app is brought back from the background without restarting.

I have been able to replicate this issue on a brand new Flutter project that uses the latest version of Flutter (3.19.2) and of the intercom_flutter package (8.1.1).

Below is the code of the only screen in my test project (sensitive data redacted):

import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:intercom_flutter/intercom_flutter.dart';

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: tap,
          child: const Text('Click me'),
        ),
      ),
    );
  }

  Future<void> tap() async {
    await FirebaseMessaging.instance.requestPermission();

    await Intercom.instance.initialize('appId', androidApiKey: 'apiKey');
    await Intercom.instance.setUserHash('userHash');
    await Intercom.instance.loginIdentifiedUser(userId: 'userId');

    await Future.delayed(const Duration(milliseconds: 1500));

    final token = await FirebaseMessaging.instance.getToken();
    if (token == null) return;
    await Intercom.instance.sendTokenToIntercom(token);

    await Intercom.instance.displayMessenger();
  }
}

And here is the pubspec.yaml file which shows all of the dependencies on this project:

name: intercom_nav_test
description: "A new Flutter project."
publish_to: 'none'

version: 1.0.0+1

environment:
  sdk: '>=3.0.5 <4.0.0'

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.6
  intercom_flutter: ^8.1.1
  firebase_core: ^2.26.0
  firebase_messaging: ^14.7.18
  flutter_native_splash: ^2.3.7

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^3.0.0
  build_runner: ^2.4.8

flutter:
  uses-material-design: true

Finally, I have attached below a video of the issue captured on my Android device (the blue screen that appears is my mock splash screen, there to indicate the app is restarting):

intercom-bug.mov
@deepak786
Copy link
Collaborator

@karim-cardeo What is the launch mode of your MainActivity in the manifest?
By default, it is "standard" and with this is the expected behavior as in the video.

Try to use the launchMode as "singleTask" or "singleInstance".
See https://developer.android.com/guide/topics/manifest/activity-element#lmode

@deepak786 deepak786 added platform-android Specific to Android platform support Asking for help writing an application labels Mar 7, 2024
@vasa137
Copy link

vasa137 commented Apr 9, 2024

I can reproduce the issue - so whenever push notification is clicked, Flutter app is restarted, if it was in the background. Everything is set up correctly (including Manifest). Can you please check how to fix that?

Looks like the Intent which is sent through the notification is restarting the app.

@deepak786
Copy link
Collaborator

What is the launch mode of your MainActivity in the manifest?

@vasa137
Copy link

vasa137 commented Apr 10, 2024

Tried both with singleTask and singleInstance, all other features are working well, so everything's correctly configured.

@deepak786
Copy link
Collaborator

I will test it at my end. But I suggest you to contact with the Intercom support as it seems to be an issue with SDK itself.

@karim-cardeo
Copy link
Author

Thanks @vasa137 @deepak786 for testing the different launch modes, I have had to disable Intercom pushes for Android as a mitigation for this issue and so I was not able to test further.

It would be good to also test this in a pure Android app with the Intercom SDK directly to see if the issue is replicable there - I will try this when I have some time. If it's replicable, we can then contact Intercom support. I have found that they are quite technical so no doubt they'd be able to help out with this.

@nikorehnback
Copy link

We just noticed this same issue, anyone found a workaround for this? In our case the app seems to restart in continuous loop causing eventually ANR.

@nikorehnback
Copy link

Anyone had time to check if this reproduces with native app or is it happening only with Flutter?

@deepak786
Copy link
Collaborator

@nikorehnback did you try with different launch modes as explained here #414 (comment)

@deepak786
Copy link
Collaborator

Does your MainActivity extends FlutterActivity or FlutterFragmentActivity?

@vasa137
Copy link

vasa137 commented Jun 3, 2024

I use FlutterFragmentActivity, and have problems

@nikorehnback
Copy link

Using FlutterFragmentActivity as well and did try with different launch modes too but didn't see any difference. Haven't had time unfortunately to create minimal sample to reproduce the bug we see.

@deepak786
Copy link
Collaborator

I will test the issue at my end. Meanwhile could you please report the issue to Intercom support directly as it seems to be an issue in native SDK.

@aman-ar
Copy link

aman-ar commented Sep 19, 2024

I have the exact same issue with my App. Launch mode of the MainActivity is singleTask
Did anybody find a workaround for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-android Specific to Android platform support Asking for help writing an application
Projects
None yet
Development

No branches or pull requests

5 participants