Intent Service Blocks calls to onHandle Intent - how to get around this
<p>In our app we have included a functionality of running a background service. It works this way <br><br> When a background service is started, an alarm manager is set which calls a broadcast receiver every 5 sec. The broadcast receiver forwards to an intent service, which then checks with the server for any updates. If an update is present, a notification is shown to the user. The problem with this is that the <code>OnHandleIntent()</code> method is blocked till the user clicks on the notification. The latest updates are not displayed to the user. How to come around this? <br><Br>
Code : </p>

<pre><code>OnHandleIntent()
{
 /*Poll the Server. If any updates are there store
  store the number of updates in sqlite database*/
  if(updates==true)
  {
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.defaults=Notification.DEFAULT_ALL;;          

   //Context context = getApplicationContext();
   CharSequence contentTitle = "Poll Notification";
   CharSequence contentText = "You have "+Integer.toString(final_count)+" Updates";
   Intent notificationIntent = new Intent(context, Home.class);

   //PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
   PendingIntent contentIntent = PendingIntent.getActivity( context, 0, notificationIntent, 0 );
   notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
   String ns = Context.NOTIFICATION_SERVICE;
   NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);


   final int HELLO_ID = 1;

   mNotificationManager.notify(HELLO_ID, notification);
  }
}
</code></pre>

<p><br>
The polling does not take place once a notiifcation is there, so the user does not get the current number of updates.<br>
Here is the code for setting the Alarm :
<br></p>

<pre><code> Calendar cal = Calendar.getInstance();
       // add 5 seconds to the calendar object
       cal.add(Calendar.SECOND, 1);
       Intent intent = new Intent(context, AlarmReceiver.class);
        PendingIntent sender = PendingIntent.getBroadcast(context, 192837, intent, PendingIntent.FLAG_UPDATE_CURRENT);
       AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
       am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),5000, sender);
       finish();
</code></pre>

<p><br></p>
