I just added the ability for a user to restore their data in my application by backing up a custom file type. When a file is opened from the file explorer with my application, my main (active) activity is opened, but in a new instance. For example, if my application is open and the recovery file is opened from the file explorer, a new instance of my application opens when I take an active action. In Android Task Manager, this is similar to my application running in file explorer, if that makes sense. Since the recovery process modifies user data, it is possible that the original instance of my application stops functioning, because it is in a data-dependent activity.
How can I prevent multiple instances of my application when it is accessed through a different intent? Thanks.
Update: I searched and still cannot find a solution. Help will be appreciated.
filter intent for my root activity in manifest:
<manifest android:launchMode="singleInstance" ... <application android:... > <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.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="file" android:pathPattern=".*\\.grdcsv" android:mimeType="*/*" android:host="*"/> </intent-filter> <!-- For email attachments --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="application/octet-stream" android:pathPattern=".*\\.grdcsv" android:scheme="content" /> </intent-filter>
source share