app_links icon indicating copy to clipboard operation
app_links copied to clipboard

Old Deeplink Triggered on Android Cold Start

Open hermuxo opened this issue 1 year ago • 1 comments

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);
      });
  }

hermuxo avatar Sep 10 '24 06:09 hermuxo

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,
  );
   });

}

bilalAppsTree avatar Sep 23 '24 06:09 bilalAppsTree

@hermuxo have you found the core issue and a fix for it?

cka29 avatar Jun 30 '25 08:06 cka29

@cka29 nope, I could not find a way to reproduce it consistently. it happens rarely and to be honest haven't seen it recently.

hermuxo avatar Jun 30 '25 08:06 hermuxo

@cka29 nope, I could not find a way to reproduce it consistently. it happens rarely and to be honest haven't seen it recently.

We have the same issue actually. The problem is that we use getInitialAppLink to correctly log campaign events to track attribution from utm_* parameters if the app was opened via universal link. However sometimes this method returns an "old" link that the app opened a while ago.

cka29 avatar Jun 30 '25 08:06 cka29

Yeah I was suprised there was no one else noticing this... But it is hard to prove. Any way you can reproduce it? I couldn't figure it out. It wasn't if app was in Doze or some background weird mode.. It was just random.

hermuxo avatar Jun 30 '25 08:06 hermuxo

I made a change to reset initial and latest links when plugin detects the attachment to an activity on the following branch: https://github.com/llfbandit/app_links/tree/cold_old_link commit ID 714f2712

If you have reproducible steps on your side, feedback is very welcome here.

llfbandit avatar Jul 03 '25 17:07 llfbandit