Intent filter launches a second instance of application

Viewed 29

I'm trying to add file association on my Android application. For that, I added the intent-filters to propose my app for the file extension needed. The AndroidManifest.xml looks as follow:

<application ...>
        <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:name="<app_url>.MainActivity" android:label="<app_name>" android:screenOrientation="portrait" android:launchMode="singleTop" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                ...
            </intent-filter>
            <intent-filter tools:ignore="AppLinkUrlError">
                <action android:name="android.intent.action.VIEW"/>
                <action android:name="android.intent.action.SEND"/>
                <action android:name="android.intent.action.SEND_MULTIPLE"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>

                <data android:mimeType="application/xml+gpx"/>
                <data android:mimeType="application/gpx+xml"/>
                <data android:mimeType="application/gpx"/>
                <data android:mimeType="text/plain"/>
                <data android:mimeType="application/xml"/>
                <data android:mimeType="text/xml"/>
                <data android:mimeType="application/octet-stream"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <action android:name="android.intent.action.SEND"/>
                <action android:name="android.intent.action.SEND_MULTIPLE"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>

                <data android:scheme="file"/>
                <data android:scheme="content"/>

                <data android:mimeType="*/*"/>
                <data android:host="*"/>
                <data android:pathPattern=".*\\.gpx"/>
            </intent-filter>

That work smoothly when the application is not running (i.e. the application is started with the intent that let me get the file url which is beeing opened.). But I got an issue if the application is already running. In this case, instead of calling onNewIntent callback of MainActivity, I have a second instance of the application that is created. I have googled and seems that the "singleTop" option should manage that but still get the same behavior. Is there anything in my manifest or in my whole approach that is wrong and can explain the issue ?

Thanks a lot for your help.

0 Answers
Related