llfbandit / app_links

Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler for Flutter.
https://pub.dev/packages/app_links
Apache License 2.0
221 stars 81 forks source link

Old Deeplink Triggered on Android Cold Start #155

Open hermuxo opened 2 months ago

hermuxo commented 2 months ago

Hi there! 😊

I'm running into a bit of a tricky issue, and I hope someone can help. Sometimes, when my Android app (using launchMode: SingleTop) is opened from the background (cold start) with a deeplink, an older link is triggered instead of the correct one. Unfortunately, I haven't been able to reliably reproduce the issue, which makes it tough to debug.

I’ve noticed it happens more often when the phone is in battery saver mode.

After reading a bit about intents, I’m wondering if the problem might be related to the intent not being cleared properly after it's handled. Would something like this help?

getActivity().setIntent(null);

Any ideas or advice would be greatly appreciated! Thanks so much! 🙏

Code called from initState()

  Future<void> initDeepLinks() async {
    _appLinks = AppLinks();
      _appLinkSubscription = _appLinks.uriLinkStream.listen((uri) {
        handleDeeplink(context, uri);
      });
  }
bilalAppsTree commented 2 months ago

i am facing the same issue when i open the link in debug mode the data inside intent if differ from the link i have generated for my deep linking

https://notis.page.link/rniX/?uid=3SlMSwdcuJNG2Ck92p4bOlYXZGl1&token=fOYnyjwdQleQS7Vy6cpLt5:APA91bHbG2oME9WduXJpHsiVIIvlchz-bIZGGjGqs1Ab02nQpSZUCA0Qp_bGWX_CuTgwLBliISvQEVNZH9tG4D-aB9E7e75kWhtFsuujJPY055v-zWBHWcdwYFpLYlHkIvdhTY7GaFaz this is the link but i am receiving Link received: https://noti.com/Noti here is my main.dart code Future initDeepLinks(UserProviderUtils? userProviderUtils) async { print('Waiting for links...'); _appLinks = AppLinks();

// Handle links from AppLinks stream
_linkSubscription = _appLinks.uriLinkStream.listen((uri) async {
  debugPrint('Link received: $uri');
  // https: //noti.com/Noti
  _globalProviderUtils?.initDynamicLinks(
    _userProviderUtils,
    deepLink: uri,
  );
   });

}