title: IllegalArgumentException: setTaskFromReuseOrCreateNewTask
body: <p>I have the next crash when I try to launch an Activity:</p>
  
  <pre><code>2019-10-24 15:12:29.887 4245-4296/fr.zapotec.eliodroid.tv E/AndroidRuntime: FATAL EXCEPTION: Thread-6
  Process: fr.zapotec.eliodroid.tv, PID: 4245
  java.lang.IllegalArgumentException: setTaskFromReuseOrCreateNewTask: task=TaskRecord{6e69142 #1643 A=fr.zapotec.eliodroid.tv U=0 StackId=1 sz=3} is in a different stack (1) than the parent of r=ActivityRecord{8062424 u0 fr.zapotec.eliodroid.tv/fr.zapotec.eliodroid.SplashActivity t1644} (0)
      at android.os.Parcel.readException(Parcel.java:1955)
      at android.os.Parcel.readException(Parcel.java:1897)
      at android.app.IActivityManager$Stub$Proxy.startActivities(IActivityManager.java:6812)
      at android.app.Instrumentation.execStartActivitiesAsUser(Instrumentation.java:1677)
      at android.app.Instrumentation.execStartActivities(Instrumentation.java:1632)
      at android.app.ContextImpl.startActivities(ContextImpl.java:910)
      at android.app.ContextImpl.startActivities(ContextImpl.java:884)
      at android.content.ContextWrapper.startActivities(ContextWrapper.java:399)
      at fr.zapotec.eliodroid.utils.LaunchActivityUtils.launchTVLastProgram(LaunchActivityUtils.java:22)
      at fr.zapotec.eliodroid.standby.StandbyManager.launchAction(StandbyManager.java:253)
      at fr.zapotec.eliodroid.standby.StandbyManager.onEventReceived(StandbyManager.java:141)
      at fr.zapotec.eliodroid.handset.HandsetEventDispatcherImpl.handleKeyPress(HandsetEventDispatcherImpl.java:229)
      at fr.zapotec.eliodroid.handset.HandsetEventDispatcherImpl.handleKeyPress(HandsetEventDispatcherImpl.java:204)
      at fr.zapotec.eliodroid.handset.HandsetEventDispatcherImpl.onMessageReceived(HandsetEventDispatcherImpl.java:165)
      at fr.zapotec.handsetbluetooth.HandsetManagerImpl.dispatchMessage(HandsetManagerImpl.java:49)
      at fr.zapotec.handsetbluetooth.MessageManager.onNewMessageReceived(MessageManager.java:119)
      at fr.zapotec.handsetbluetooth.HandsetThread.listenAndWrite(HandsetThread.java:126)
      at fr.zapotec.handsetbluetooth.HandsetThread.run(HandsetThread.java:56)
  </code></pre>
  
  <p>This is the Manifest file:</p>
  
  <pre><code>        &lt;activity
          android:launchMode="singleTask"
          android:name=".SplashActivity"
          android:noHistory="true"
          android:theme="@style/SplashTheme"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;category android:name="android.intent.category.HOME" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;category android:name="android.intent.category.LEANBACK_LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:launchMode="singleTask"
          android:noHistory="true"
          android:name=".StandbyActivity"/&gt;
      &lt;activity
          android:launchMode="singleTask"
          android:name=".main.SimpleMainActivity"/&gt;
      &lt;activity
          android:launchMode="singleTask"
          android:name=".main.InstallActivity"/&gt;
  </code></pre>
  
  <p>I need the Activity 'SimpleMainActivity' to be one only instance (that's why the 'singleTask')
  This Activity can be launched due to Bluetooth events (triggered by a bluetooth device) or due to a given timing in a very specific situation.</p>
  
  <p>The method which launches the Activity is:</p>
  
  <pre><code>startActivity(new Intent(context, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
  </code></pre>
  
  <p>I have the crash when trying to launch the Activity from the 2 different sources almost at the same time.</p>
  
  <p>Anyone knows how to solve this problem without removing the 'singleTask' from my Activity?</p>
  
  <p>For information, my application is the "Default launcher", so "SplashActivity" maybe be launched if system needs to show the launcher. The SplashActivity only shows a splash screen and launches the first activity (SimpleMainActivity.class) </p>