Search code examples
androidandroid-activitylaunchmode

singleTask launch mode is not working


Having this weird problem of multiple instances of my activity getting created even after specifying the launchMode as singleTask. Has anybody faced this issue ? Any pointers will be appreciated.

Below is how i have declared my activity in the manifest:

    <activity
    android:name="com.test.TestActivity"
        android:launchMode="singleTask">
     <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />

                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="*/*" />
            </intent-filter>
</activity>

And this is how i am launching my activity while it is still in foreground:

Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, sharedText);
        sendIntent.setType("text/plain");
        activity.startActivity(Intent.createChooser(sendIntent, "Share"));

Android version that i am testing it on is 5.1.1


Solution

  • So it seems the issue is with device. On emulator and other devices with same android version singleTask works just fine.