handling Intents on PhoneGap - avoiding re-launch

edited August 2012 in Packaging Apps
I would like to use Intents on Android for my PhoneGap based application, to register for an Intent and handle that event and its data in my Enyo application.

I have used the WebIntents plugin. I setup AndroidManifest.xml to successfully register for "myprotocol://host/path" and have that callback into the the app.

But currently this appears to restart the application each time. My app comes to the forground, but appears to start up from scratch and get url as the launch parameter in window.plugins.webintent.getUri().

I'd like to be able to pass data to and already-running app via intents. The goal here is a web page with a link to a URL that launches back to the app - brings it to the foreground and takes action based on the data passed back.

Do I need to specify multiple activities somehow in AndroidManifest.xml?
Or somehow setup the intent to not launch the Main activitity again?

I currently have something like this in AndroidManifest.xml:
<application android:icon="@drawable/icon" android:label="@string/app_name"
    android:debuggable="true">

    <activity android:name="MyApp" android:label="@string/app_name" 
              android:screenOrientation="portrait"
              android:configChanges="orientation|keyboardHidden">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>
          <data android:scheme="myprotocol" />
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.BROWSABLE" />
          <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

    </activity>
</application>

Comments

  • And to answer my own question, it appears I just needed android:launchMode="singleTop" as a parameter to the activity.

    Then I get the url back in the onNewIntent() call.



  • So I've discovered this works on a HTC One X with Android 4.0.4 (with HTC Sense), but does NOT work correctly on a Galaxy Nexus - running either 4.0.4 as well, or running 4.1.1

    This is with PhoneGap 2.0 and Enyo 2.0.1

    On the "stock" android devices, the above intent filter causes PhoneGap to create a new instance of the app, *IN* the Browser.

    So where it should re-launch my already-running app instance, instead it starts a second.

    But even better, this second instance takes over the UI of the Browser application. My PhoneGap application is literally now the current Browser activity. Showing the task switcher, shows my app UI, but a Browser app icon.


    Am I doing something incorrect in hooking up the intent-filter this way?

    How can I trigger the existing app instance to be launched, instead of a new one in the browser, on stock android 4.x?
Sign In or Register to comment.