Two Instances opened When opening application from dynamicaLink and from launcher icon?

655 Views Asked by At

I ran into an issue in my Android Application where whenever I open my app through a dynamic link shared on Whatsapp, it will open in the same Whatsapp Application. I can see by going to the recent task that there is only one Application in a recent task which is Whatsapp and I can see my application inside it.

If I open my app from launcher icon then it will also create a new Application and there will be two application in recent tasks. My Splashscreen looks like this -

<activity
            android:name=".SplashScreen"
            android:screenOrientation="portrait"
            android:theme="@style/SplashTheme"
            android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</activity>
2

There are 2 best solutions below

0
On

In general it is better to use a dedicated Activity for sharing from other applications. Another app should not launch your main (root) Activity to share, it should launch a different Activity. That Activity can then launch your main (root) Activity in a new task (if necessary). You need to consider the user's behaviour and make sure that you don't confuse the user with multiple tasks.

1
On

You should added attribute in your activity

android:launchMode="singleTask"