I have an Android application based on Cordova / PhoneGap 2.0, and I use intent filters to register a special protocol handler.
So, my PhoneGap application launches, does its work, and then accesses the browser application on a remote web page (via navigator.app.loadUrl('http://example.com/') or window.open('http://example.com/')) ). The link to this remote webpage in the browser ( myprotocol://do/stuff ) will bring my application back to the forefront using an intent filter for the data scheme. And through the WebIntents plugin, I can get and parse this url in my application.
This works in Android 4.0.4 on HTC One X (and therefore in the Android version of Sense).
The same code does not work on Android 4.0.4 or 4.1.1 on Galaxy Nexus, or 4.0.1 on Nexus S.
The odd problem that I see on Android Android is that when I launch the intent filter, it launches a new kind of application in the Android browser. I see that it reloads the html page. This does not bring the existing application example to the forefront as expected. Looking at logcat, I see that it is actually the same I / Web Console process, but it loaded the html again. There is no new journal "Start proc".
And oddly enough, now I have two instances of my application displayed in the task manager. The original application instance still exists with my custom application icon. And the browser has its own browser application icon, but the user interface of the application obviously works. I can switch and interact with each webview separately. It is almost like my process now has two web views - one in the application and the second web view, now launched in the browser process.
I currently have something similar in AndroidManifest.xml:
<activity android:name="MyApp" android:label="@string/app_name" android:screenOrientation="portrait" android:launchMode="singleTop" 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>
My application uses the WebIntents plugin and the NFC plugin, but I also see the same problem without them. I also reproduced this problem in PhoneGap 1.8.1 and 1.9.0.
I can also look through the log that for HTC, DroidGap.onCreate() not called when the intent is launched, but on Nexus it does.
Am I doing something wrong in connecting an intent filter this way?
How can I run an existing application instance to call instead of a new one in a browser on Android 4.x?