title: BroadCast Services and Notification's in Status Bar
body: <p>Edit : I am going to ask my question in a different way again since i recieved any reply.</p>
  
  <p>I think two problems caused by puting  alarm manager ,which the  broadcast receiver  is called by its pendingIntent, in Mainactivity . first whenever the app open it will be called then the notification shows up .
   secondly when the app is closed the notifications may not be called since they called in main activity ( or as they are braodcast they should be runned any way !!!!)
  if so ,the question is where else can I put it ?   </p>
  
  <p>I am going to develop a TODO list as one feature in my application. I would like to notify user even if the app has not been running so I am using Broad cast services in which the service is called via my Main activity like below :</p>
  
  <pre><code>public void NOtifyMe( ArrayList&lt;String&gt; mArrayList)
  {
          AlarmManager alarmMang = (AlarmManager) getSystemService(ALARM_SERVICE);
  
          // ---get current date and time---
  
          Calendar calender = Calendar.getInstance();
          calender.add(Calendar.SECOND, 20);
  
          Intent noteIntent = new Intent(MainActivity.this, BroadCast.class);
          noteIntent.putStringArrayListExtra("ArrayList", mArrayList);//.putExtra("Cursor",c/*"ID", id*/);
          PendingIntent pendI = PendingIntent.getBroadcast(MainActivity.this, 0,
                  noteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  
          // // SET ALARM
  
          alarmMang.set(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(),
                  pendI);
          alarmMang.setRepeating(AlarmManager.RTC, System.currentTimeMillis(),
                  AlarmManager.INTERVAL_DAY, pendI);
  </code></pre>
  
  <p>and here is my Broad cast services code :</p>
  
  <pre><code>public void onReceive(Context arg0, Intent arg1) {
  
      // TODO Auto-generated method stub
      ArrayList&lt;String&gt; array = arg1.getStringArrayListExtra("ArrayList");
      Intent intent = new Intent();
      intent.setClassName("com.Sali.todolist_final", "com.Sali.todolist_final.notifyService");
      //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.putStringArrayListExtra("ArrayList", array);
      arg0.startService(intent);
  
  }
  </code></pre>
  
  <p>As you can see I am using array list , because it has not shown two notification in case there was two upcoming task. i was trying to do it first by calling the function as much as i had record in my Cursor.</p>
  
  <p>here is the code in notifyService:</p>
  
  <pre><code>    for (int i = 0; i &lt; array.size(); i++) {
  
          id = array.get(i);// .getLong(inId.getColumnIndex("_id"));//
                              // Long.valueOf(inId);
          g = Integer.parseInt(id);
          idtopass = Long.valueOf(id);
          counter = 0;
          Intent mainIntent = new Intent(notifyService.this, TaskDetail.class);
          mainIntent.putExtra("id", idtopass);
          //mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          mainIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
          PendingIntent pIntent = PendingIntent.getActivity(
                  notifyService.this, g, mainIntent,
                  PendingIntent.FLAG_UPDATE_CURRENT);
  
          NotificationCompat.Builder builder;
          NotificationManager notificationManager;
  
          builder = new NotificationCompat.Builder(notifyService.this)
  
          .setSmallIcon(R.drawable.ic_launcher).setContentTitle("TO_Do")
                  .setContentText("You Have Something To Do." + id);
          builder.setAutoCancel(true);
          builder.setContentIntent(pIntent).setNumber(++counter);
  
          notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  
          notificationManager.notify(g, builder.build());
  
      }
  </code></pre>
  
  <p>Here I have two big problem :
  first : it does not show the notification without app being run
  second : as i set the proper flags , by clicking on the notification , it will appear again.
  third (less important fot time being ) I dont like two have two notification icon in case there are 2 upcoming but i like by opening the window,user can see both . i know it is becouse i use Manager.notify in the for body ,but no other way for me in these case.if anyone has a solution for that as well.
  I appriciate if someone can help me out here. It is really urgunt .</p>