title: Android: Understanding using one IntentService with multiple actions
body: <p>I have a problem with intent not getting delivered to an <code>IntentService</code> under a specific activity flow: This is the scenario:</p>
  
  <ol>
  <li>Consider 3 activities, Home, B and C. C has 2 fragments CF1 and CF2. </li>
  <li>B, CF1 and CF2 use the same IntentService class but with different actions. </li>
  <li>IntentService gets started using <code>startService(Intent)</code>. (getActivity().startService(Intent) for Fragments)</li>
  <li>Wherever IntentService gets started, I make sure it gets stopped using <code>stopService(intent)</code> if it is running in Activity/Fragment's <code>onStop()</code>.</li>
  <li>If the activity flow is Home -> C - > CF1 - >CF2, everything works.</li>
  <li>If the activity flow is Home -> B - > C -> CF1 - > CF2, then <code>onHandleIntent</code> is never invoked after startService(Intent) from CF2. B and CF1 intents are handled. For debugging, I tried by waiting for IntentService to complete in Activity B and then go to CF1 -> CF2, still the same problem. CF1 never seems to have any problems in starting the same intent service. When I tried creating a new <code>IntentService</code> class for CF2, it worked.</li>
  </ol>
  
  <p>My understanding was that IntentService has a queue for intents. If the service is running for first time , onStartCommand is invoked (which we are not supposed to handle for IntentService). If the service is already running, onHandleIntent is invoked for every subsequent call of startService. </p>
  
  <p>Obviously, I am doing something wrong but not clear as what. I have tried looking into other stackoverflow questions but didn't help. The code I am using is pretty straightforward:</p>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;service android:name=".service.ExampleIntentService" /&gt;
  </code></pre>
  
  <p><strong>Activity B</strong></p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState)
  {
         .......
         intent = new Intent(getApplicationContext(), ExampleIntentService.class);
         intent.setAction(StringConstants.ACTION_B);
         serviceRunning = true; //set to false in onReceiveResult 
         startService(intent);
  }
  
  @Override
  public void onStop()
  {
        if(serviceRunning &amp;&amp; intent != null)
            stopService(intent)
  }
  </code></pre>
  
  <p><strong>Fragment CF1</strong></p>
  
  <pre><code>@Override
  public void onResume()
  {
      super.onResume();
  
      intent = new Intent(getActivity(), ExampleIntentService.class);
      intent.setAction(StringConstants.ACTION_CF1);
      serviceRunning = true; //set to false in onReceiveResult 
      startService(intent);
  }
  
  @Override
  public void onStop()
  {
        if(serviceRunning &amp;&amp; intent != null)
            stopService(intent)
  }
  </code></pre>
  
  <p>The code is exactly the same for fragment, CF2</p>