title: How to open activity from widget like this: if app is not open, open main activity too but if app is open, just open on top of the current activity?
body: <p>Basically I want the user to be able to hit back and reach my main activity at some point. So here are the two senarios:</p>
  
  <ol>
  <li>If the app is already open, then the widget will just launch the app and start the activity on top of it. </li>
  <li>If the app is not open, I want the main activity to be already present in the back stack.</li>
  </ol>
  
  <p>Is this possible? I think for senario 2 the code would look like this right:</p>
  
  <pre><code>Intent mainActivityIntent = new Intent(context, MainActivity.class);
  mainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); //this basically starts the app from fresh (i.e. clears current activities)
  
  Intent addCruisesIntent = new Intent(context, SecondActivity.class);
  addCruisesIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK ); //this basically starts the app from fresh (i.e. clears current activities)
  
  Intent[] intents={mainActivityIntent,addCruisesIntent};
  Intent[] intents={addCruisesIntent};
  
  PendingIntent pendingIntent = PendingIntent.getActivities(context, 0, intents, 0);
  </code></pre>
  
  <p>I was wondering if there was a flag or a combination of flags that can achieve what i want.</p>