darryncampbell / darryncampbell-cordova-plugin-intent

General purpose intent shim layer for cordova appliations on Android. Handles various techniques for sending and receiving intents.
MIT License
86 stars 130 forks source link

Intents looping repeatedly #125

Open micahlt opened 3 years ago

micahlt commented 3 years ago

This plugin works perfectly and I thank you so much for it!

However, I'm experiencing some issues with intents occurring multiple times. My context is an unofficial mobile client for the children's programming site Scratch. I'm using this plugin to offer users the opportunity to forward links from the Scratch website directly to the app. Opening with my app works fine, but when you select "Open with Chrome", the "open with" popup appears up to four or five times before it finally opens the site. Any ideas of what could be causing this? Here's my only implementation of your plugin:

import {
  isPlatform
} from '@ionic/vue';

if (isPlatform('android')) {
      try {
        window.plugins.intentShim.onIntent(function(intent) {
          let uri = utils.matchRegexes(intent.data);
          if (uri.type == "homepage") {
            return 0;
          } else if (uri.type == "project" || uri.type == "studio") {
            window.location.replace(`/tabs/tab1?${uri.type}=${uri.id}`);
          }
        });
      } catch {
        console.error('Could not find Android Intent Shim plugin - see https://ionicframework.com/docs/native/web-intent');
      }
    }
darryncampbell commented 3 years ago

Hi, are you able to debug your code and determine if / why https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent/blob/master/src/android/IntentShim.java#L642 is being invoked multiple times? That onIntent() method should just map to https://developer.android.com/reference/android/app/Activity#onNewIntent(android.content.Intent) but I see logic in the code related to deferred / delayed firing so it is possible something is going wrong there.

KoenLav commented 2 years ago

This may be related: we are experiencing startActivityForResult firing multiple times (on some occasions).

darryncampbell commented 2 years ago

@KoenLav are there reproducible reproduction steps?

KoenLav commented 2 years ago

I'm now thinking it may have to do with us not providing a requestCode, because of which 1 is used by default, but it seems requestCode is like an 'Intent identifier' rather than 'just' the code it returns.

Testing that theory now.