title: Application abnormal behavior does not start activity mentioned in intent
body: <p>I have 3 major class in the application</p>
  
  <p>1) Intent service: where I receive push notification and open activity according to notification message and other two classes behavior. below is the code which does that</p>
  
  <pre><code> if(Global.isMainScreenRunning){
     Intent intent = new Intent(this, MainScreen.class);
     intent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
     startActivity(intent);
  } else if(!Global.NotificationScreenRunning){
     Intent intent = new Intent(this, NotificationScreen.class);
     intent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
     startActivity(intent);
  }
  </code></pre>
  
  <p>2) NotificationScreen : This is the mediator screen so if the application is not running this screen will be shown first and on click of yes button of this screen MainScreen will be opened and this screen will be finished.</p>
  
  <p>3) Main screen: This is the main screen of the application which show map. its core behavior is that ts a <code>launchmode="singletask"</code> mentioned in menifest file, which means if this screen is running its hole data will be sent to <code>onNewIntent()</code> method rather than opening this screen again.</p>
  
  <p>Now what is happening in flow is</p>
  
  <p>Step 1: application is in background and push notification comes. condition run and the second condition gets success and notification screen intent is shot</p>
  
  <p>step 2: In notification screen I click on ye button to move on to the next main screen</p>
  
  <p>step 3: In Main screen I process this info and perform task or just close the application</p>
  
  <p>Step 4: again a new notification is received and as the application is not running is goes to second condition and start the intent for notification screen but this time no notification screen is launched instead of providing its intent and main screen is launched which is wrong.</p>
  
  <p>This is the abnormal behavior which I am facing that instead of providing class of notification screen for intent main screen is launched which is totally different behavior of application according to android.</p>
  
  <p>Any help from any one who come across such problem will be greatly appreciated.</p>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.app"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="15"
          android:targetSdkVersion="18" /&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt;
      &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  
      &lt;uses-feature android:name="android.hardware.camera" /&gt;
      &lt;uses-feature android:name="android.hardware.camera.front" /&gt;
      &lt;uses-feature android:name="android.hardware.camera.autofocus" /&gt;
      &lt;uses-feature android:name="android.hardware.microphone" /&gt;
  
      &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
      &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
  
      &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  
      &lt;permission android:name="com.example.app.permission.C2D_MESSAGE"
          android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="com.example.app.permission.C2D_MESSAGE" /&gt;
  
      &lt;supports-screens
          android:largeScreens="true"
          android:normalScreens="true"
          android:smallScreens="true"
          android:xlargeScreens="true" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/android_app_icon"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".SplashScreen"
              android:configChanges="keyboardHidden|orientation"
              android:label="@string/app_name"
              android:screenOrientation="portrait" &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;
          &lt;/activity&gt;
  
          &lt;activity
              android:name=".MainScreen"
              android:configChanges="keyboardHidden|orientation"
              android:launchMode="singleTask"
              android:excludeFromRecents="true"
              android:screenOrientation="portrait" &gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".NotificationScreen"
              android:configChanges="keyboardHidden|orientation"
              android:excludeFromRecents="true"
              android:screenOrientation="portrait" &gt;
          &lt;/activity&gt;
  
          &lt;receiver
              android:name=".pushnotification.GcmBroadcastReceiver"
              android:permission="com.google.android.c2dm.permission.SEND" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
                  &lt;category android:name="com.selebrety.app" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
          &lt;service android:name=".pushnotification.GcmIntentService" /&gt;
  
          &lt;meta-data android:name="com.google.android.gms.version"
             android:value="@integer/google_play_services_version" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>Second Edit</strong></p>
  
  <p>The mobile in which I am testing is "YU Yureka" here is its specification <a href="http://www.gsmarena.com/yu_yureka-6987.php">link</a>. Current it have android 5.0.2 OS</p>
  
  <p><strong>Third Edit</strong></p>
  
  <p>To test this behavior I have debugged the code from eclipse debugger. To check this I have put a break point in <code>NotificationScreen</code> <code>onResume</code> and <code>onCreate</code> but it was never hit instead of <code>onResume</code> of <code>MainScreen</code> is hit. </p>
  
  <p>Also I added a logs in if and else condition but still logs for else condition is printed.</p>
  
  <p><strong>Fourth Edit</strong>
  <code>Global.isMainScreenRunning</code>: is global <code>boolean</code> variable which is done false in <code>onPause</code> of <code>MainScreen</code> and done true in <code>onResume</code> of <code>MainScreen</code>.</p>
  
  <p><code>Global.NotificationScreenRunning</code>: is global <code>boolean</code> variable which is done false in <code>onPause</code> of <code>NotificationScreen</code> and done true in <code>onResume</code> of <code>NotificationScreen</code>.</p>