title: android : How to work around the fact that a singleInstance activity cannot expect to rely onActivityResult when starting subActivity?
body: <p>I am making an android application, which has the following execution flow:</p>
  
  <ol>
  <li><p>A service registers a PendingIntent with the AlarmManager</p></li>
  <li><p>When the alarm is launched, a <code>Receiver</code> receives the intent, and (given some conditions) calls <code>startsActivity()</code> for my <code>Main Activity</code>, which in the manifest has been declared as     <code>android:launchMode="singleInstance"</code>. Note that for this call to work, the intent passed should have an <code>Intent.FLAG_ACTIVITY_NEW_TASK</code></p></li>
  <li><p>When started, <code>Main Activity</code> modifies itself a bit, and calls <code>startActivityForResult</code> for an Activity, which we'll call <code>WebviewActivity</code> (because it contains a webview, but that's besides the point)</p></li>
  <li><p>When the user is done interacting with the<code>WebViewActivity</code>, <code>setResult()</code> and <code>finish()</code> are called on it, and one would expect for <code>MainActivity.onActivityResult()</code> to be called. </p></li>
  </ol>
  
  <p>But of course this does not happen, as has been documented in many discussions here, the reason apparently being that an Activity launched from a <code>singleInstance</code> Activity, runs in a different Task.</p>
  
  <p>A solution I think would be to have the <code>WebActivity</code> start the <code>MainActivity</code> instead.</p>
  
  <p>The question is, is there a way to maintain <code>onActivityResult</code> being called at the right time? In that case, which aspects from the starting point of the execution flow should change? </p>
  
  <p>Please note that <code>MainActivity</code> should not have multiple instances at the same time (it is basically an interface to the service) but if its <code>launchMode</code> is set to <code>standard</code>, the Receiver, because of the <code>FLAG_ACTIVITY_NEW_TASK</code> that is required, will do just that.</p>
  
  <p>Manifest declaration of <code>MainActivity</code>:</p>
  
  <pre><code>    &lt;activity   android:name=".activities.MainActivity"
                  android:label="@string/app_name" 
                  android:launchMode="singleInstance"
                  android:configChanges="keyboardHidden|orientation|screenSize"&gt;
  
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
  
          android:uiOptions=”splitActionBarWhenNarrow”
      &lt;/activity&gt;
  </code></pre>
  
  <p>Receiver launches <code>MainActivity</code> by calling</p>
  
  <pre><code> onReceive(Context context, Intent intent) 
   {
       intent.setClass(context, MainActivity.class);
       int flag = Intent.FLAG_ACTIVITY_NEW_TASK;
       intent.setFlags(flag);
       context.startActivity(intent);
   }
  </code></pre>