Android-runtime: [Deeplink] android app relaunching everytime from Firefox.

Created on 18 Feb 2017  路  1Comment  路  Source: NativeScript/android-runtime

This problem is easily reproduced by cloning https://github.com/NativeScript/nativescript-marketplace-demo master branch and updating Android manifest file's application->activity section with following extra xml content.

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

after making changes run

tns platform remove android
tns platform add android
tns run android

and open app by entering marketdemo:// in browser. I am using Firefox

  • CLI: 2.5.0
  • Cross-platform modules: 2.4.0
  • Runtime(s): 2.5.0

Testing on Samsung S7.

After opening via Firefox this is how it looks on S7. As you can see app is already open(top) but a new instance of app has launched inside FF(bottom)

The above mentioned issue is not present when using Chrome as app

screenshot_20170218-161454

question

Most helpful comment

Hey @zahid-dapperapps

In your AndroidManifest.xml in the activity where your intent is set (for the NativeScript application it is usually activity with name _com.tns.NativeScriptActivity_ you should set the following key

android:launchMode="singleTask" 

When this key is set Android will either use the existing instance or open a new one when needed. The absence of this key will cause the side effect when your application is loaded multiple times

Here is how my activity looks after the key was applied like in AndroidManifest.xml

<activity
    android:name="com.tns.NativeScriptActivity"
    android:label="@string/title_activity_kimera"
    android:launchMode="singleTask"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:screenOrientation="sensorPortrait">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="marketdemo" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

>All comments

Hey @zahid-dapperapps

In your AndroidManifest.xml in the activity where your intent is set (for the NativeScript application it is usually activity with name _com.tns.NativeScriptActivity_ you should set the following key

android:launchMode="singleTask" 

When this key is set Android will either use the existing instance or open a new one when needed. The absence of this key will cause the side effect when your application is loaded multiple times

Here is how my activity looks after the key was applied like in AndroidManifest.xml

<activity
    android:name="com.tns.NativeScriptActivity"
    android:label="@string/title_activity_kimera"
    android:launchMode="singleTask"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:screenOrientation="sensorPortrait">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="marketdemo" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
Was this page helpful?
0 / 5 - 0 ratings