intercom_flutter icon indicating copy to clipboard operation
intercom_flutter copied to clipboard

Intercom push notification freezes/recalls main() when enters foreground in Android flutter (Conflicts with branch.io)

Open pankaj-goa opened this issue 1 year ago • 2 comments

Description In our flutter application, on the android platform when we try to tap on the intercom push notification while the app being in killed or in background, it just opens the app and freezes the screen on splash(in killed state) or freezes current screen(incase was in background) This happens only when there is this package i.e: branch.io initialized in main().

Note: this happens only on the android, while on iOS we do not face this issue.

Flutter doctor output: [✓] Flutter (Channel stable, 3.19.4, on macOS 14.2 23C64 darwin-arm64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2023.1) [✓] Connected device (3 available) [✓] Network resources

Flutter pub get output

pankaj@Pankajs-Laptop example % flutter pub get
Resolving dependencies... 
! intercom_flutter 9.0.1 from path .. (overridden)
! intercom_flutter_platform_interface 2.0.0 from path ../../intercom_flutter_platform_interface (overridden)
! intercom_flutter_web 1.1.1 from path ../../intercom_flutter_web (overridden)
  leak_tracker 10.0.0 (10.0.5 available)
  leak_tracker_flutter_testing 2.0.1 (3.0.5 available)
  leak_tracker_testing 2.0.1 (3.0.1 available)
  material_color_utilities 0.8.0 (0.11.1 available)
  meta 1.11.0 (1.14.0 available)
  test_api 0.6.1 (0.7.1 available)
  vm_service 13.0.0 (14.2.1 available)
Got dependencies!

Relavant code:

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();
  if (await Intercom.instance.isIntercomPush(message.data)) {
    await Intercom.instance.handlePush(message.data);
    return;
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  /// Initialize Branch SDK , uncomment this to reproduce the error
  await FlutterBranchSdk.init(
      useTestKey: false,
      enableLogging: false,
      disableTracking: false);


  // TODO: make sure to add keys from your Intercom workspace.
  debugPrint("END branch integration and start intercom init");
  await Intercom.instance.initialize(
    'app-id-xxx',
    androidApiKey: 'android_sdk- xxxx',
    iosApiKey: 'ios_sdk-xxxx',
  );
  final firebaseMessaging = FirebaseMessaging.instance;
  FirebaseMessaging.onBackgroundMessage( _firebaseMessagingBackgroundHandler);
  final intercomToken = Platform.isIOS ? await firebaseMessaging.getAPNSToken() : await firebaseMessaging.getToken();
  Intercom.instance.sendTokenToIntercom(intercomToken!);
  runApp(SampleApp());
}

pankaj-goa avatar Apr 22 '24 10:04 pankaj-goa

@pankaj-goa It may be an issue with Branch SDK.

What is your MainActivity launchMode in AndroidManifest? By default, it is "standard". In the configure app section on branch docs, they are using "singleTask" launch mode. Maybe you can try that.

For various launch modes, you can read here https://developer.android.com/guide/topics/manifest/activity-element#lmode

deepak786 avatar Apr 24 '24 19:04 deepak786

@deepak786 I confirm launchMode was set to "singleTask" and configured properly as per branch SDK documentation.

pankaj-goa avatar Apr 29 '24 09:04 pankaj-goa

Closed here

pankaj-goa avatar May 24 '24 10:05 pankaj-goa