title: Android: Application multiple instances
body: <p>When I launch my application from launcher following <strong>sequence</strong> takes place:</p>
  
  <ol>
  <li><p><code>SplashActivity.java</code> </p>
  
  <pre><code>&lt;activity
    android:name=".splash.SplashActivity"
    android:launchMode="singleTop"
    android:screenOrientation="portrait"
    android:theme="@style/SplashActivityTheme"&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;
  </code></pre>
  
  <p></p></li>
  <li><p><code>HomeActivity.java</code></p>
  
  <p></p></li>
  </ol>
  
  <p><strong>Steps to reproduce the Problem:</strong></p>
  
  <ol start="3">
  <li><p>Application is not running in the background nor is in the pause state.</p></li>
  <li><p>Notification is received and is shown on the status bar.</p></li>
  <li><p>User clicks on the notification and <code>HomeActivity.java</code> is launched.</p>
  
  <p>
      
        
      
    </p>
  
  <p><code>FirebaseMessagingService.java</code></p>
  
  <pre><code>private void sendNotification(String messageBody, String title) {
  
      Intent intent = new Intent(this, HomeActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
      PendingIntent pendingIntent =
          PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
  
      Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      NotificationCompat.Builder notificationBuilder =
          new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_ic_notification)
              .setContentTitle(title)
              .setContentText(messageBody)
              .setAutoCancel(true)
              .setSound(defaultSoundUri)
              .setColor(ContextCompat.getColor(this, R.color.pantone_375))
              .setContentIntent(pendingIntent);
  
      NotificationManager notificationManager =
          (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
      notificationManager.notify(++count /* ID of notification */, notificationBuilder.build());
  }
  </code></pre></li>
  <li><p>Leave the <code>HomeActivity.java</code> open and launch the application from launcher. Another instance of the same application launches and the sequence is <code>SplashActivity.java</code> -> <code>HomeActivity.java</code>. </p></li>
  </ol>
  
  <p><strong>Expected Result</strong></p>
  
  <ol>
  <li><p>One instance of the application should exists at any given point.</p></li>
  <li><p>If the application is already in open state and user is on <code>HomeActivity.java</code> then it should receive the focus.</p></li>
  <li><p>Application is launched by clicking on the notification and application is in an open state. User clicks on the launcher icon, then the old application instance should gain focus.</p></li>
  </ol>