React Native Android launchMode singleTask getLaunchOptions doesn't get called again

Viewed 921

I am developing a react-native app for Android. The app takes image sharing with this intent-filter on the main activity

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
    android:launchMode="singleTask"
    android:windowSoftInputMode="adjustResize">
    <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_MULTIPLE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
    </intent-filter>
</activity>

I am able to get the initial sharing intent images by overriding getLaunchOptions(), but with this default launchMode="singleTask", I am not able to get new sharing intent when I have the existing instance of the app running.

So, how can I get the new sharing intent while have an instance of the app running?

PS: changing the launchMode to standard to standard kind of solved my problem, but that will create multiple instances of the app.

4 Answers
 <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>

I have the same problem. If the launchMode isn't in AndroidManifest.xml the situation is like standart.

I've found a solution for my case (receiving intents for .txt files) In AndroidManifest.xml

      android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
      android:launchMode="singleTask"
      ...
      <intent-filter tools:ignore="AppLinkUrlError">
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <data android:mimeType="text/*" />
      </intent-filter>

In MainActivity.java

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      ...
      onNewIntent(this.getIntent());
  }

   @Override
   public void onNewIntent(Intent intent) {
       super.onNewIntent(intent);
       // here are received intents
   }

In such way I receive intents when app in background or it is not run at all and only ONE instance of the app.

Related