title: Show multiple notification
body: <p>I am trying to implement a remainder concept in my app which airs a TV channel. Concept is that the user can set remainder for certain TV programs and the app shows a notification 5mins before the program airs on the channel. I am using the combination of <code>AlarmManager</code>, <code>BroadcastReceiver</code> and Service to handle the notification part. </p>
  
  <p><strong>Requirement:</strong> Show separate notification for different remainders. i.e. when user sets remainder for 15:26 and 15:27 then the app must show two notifications at 15:21 and 15:22 </p>
  
  <p><strong>Problem:</strong> I am getting only one notification which is updated for all other remainders. i.e. app shows notification for 15:26 remainder and same notification is updated for 15:27</p>
  
  <p>So friends help me with my problem. </p>
  
  <p>Following is the just the sample app to perform above mentioned task:</p>
  
  <p><a href="https://i.stack.imgur.com/3jtHd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3jtHd.jpg" alt="enter image description here"></a></p>
  
  <p>Here are my classes:</p>
  
  <p><em>MainActivity.java</em></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  TextView time1, time2, time3, time4, time5, time6;
  Button button1, button2, button3, button4, button5, button6;
  Intent intent;
  String endTime;
  
  AlarmManager alarmManager;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  
      time1 = findViewById(R.id.time1);
      button1 = findViewById(R.id.button1);
      time2 = findViewById(R.id.time2);
      button2 = findViewById(R.id.button2);
      time3 = findViewById(R.id.time3);
      button3 = findViewById(R.id.button3);
      time4 = findViewById(R.id.time4);
      button4 = findViewById(R.id.button4);
      time5 = findViewById(R.id.time5);
      button5 = findViewById(R.id.button5);
      time6 = findViewById(R.id.time6);
      button6 = findViewById(R.id.button6);
  
      time1.setText("15:26");
      time2.setText("15:27");
      time3.setText("15:28");
      time4.setText("15:29");
      time5.setText("15:30");
      time6.setText("15:31");
  
      button1.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
  
              Intent intent = new Intent("com.newitventure.remainder.START");
              int id = (int) System.currentTimeMillis();
              intent.setClass(MainActivity.this, ServiceRestarterBroadcastReceivers.class);
              intent.putExtra("id", id);
              intent.putExtra("time", time1.getText().toString());
              PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
              alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60 * 1000, pi);
          }
      });
  
      button2.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent("com.newitventure.remainder.START");
              int id = (int) System.currentTimeMillis();
              intent.setClass(MainActivity.this, ServiceRestarterBroadcastReceivers.class);
              intent.putExtra("id", id);
              intent.putExtra("time", time2.getText().toString());
              PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
              alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60 * 1000, pi);
          }
      }); 
      button3.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent("com.newitventure.remainder.START");
              int id = (int) System.currentTimeMillis();
              intent.setClass(MainActivity.this, ServiceRestarterBroadcastReceivers.class);
              intent.putExtra("id", id);
              intent.putExtra("time", time3.getText().toString());
              PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
              alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60 * 1000, pi);
          }
      }); 
      button4.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent("com.newitventure.remainder.START");
              int id = (int) System.currentTimeMillis();
              intent.setClass(MainActivity.this, ServiceRestarterBroadcastReceivers.class);
              intent.putExtra("id", id);
              intent.putExtra("time", time4.getText().toString());
              PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
              alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60 * 1000, pi);
          }
      }); 
      button5.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent("com.newitventure.remainder.START");
              int id = (int) System.currentTimeMillis();
              intent.setClass(MainActivity.this, ServiceRestarterBroadcastReceivers.class);
              intent.putExtra("id", id);
              intent.putExtra("time", time5.getText().toString());
              PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
              alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60 * 1000, pi);
          }
      }); 
      button6.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent("com.newitventure.remainder.START");
              int id = (int) System.currentTimeMillis();
              intent.setClass(MainActivity.this, ServiceRestarterBroadcastReceivers.class);
              intent.putExtra("id", id);
              intent.putExtra("time", time6.getText().toString());
              PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
              alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60 * 1000, pi);
          }
      });
  
    }
  }
  </code></pre>
  
  <p><em>ServiceRestarterBroadcastReceivers.java</em></p>
  
  <pre><code>public class ServiceRestarterBroadcastReceivers extends BroadcastReceiver {
  
  Context context;
  long millis;
  
  @Override
  public void onReceive(Context context, Intent intent) {
  
      this.context = context;
  
      String action = intent.getAction();
  
      if (action.equalsIgnoreCase("com.newitventure.remainder.STOP_SERVICE")) {
          context.stopService(intent);
      } else {
          final String programTime = intent.getStringExtra("time");
          final int id = intent.getIntExtra("id", 0);
  
          millis = System.currentTimeMillis();
  
          calculateMinute(programTime, id);
  
      }
  
  }
  
  private void calculateMinute(String programTime, int id) {
  
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
      Date startTime = new Date();
      Date endTime = new Date();
  
      try {
          startTime = simpleDateFormat.parse(simpleDateFormat.format(millis));
          endTime = simpleDateFormat.parse(programTime);
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      long difference = endTime.getTime() - startTime.getTime();
  
      if (difference &lt; 0) {
          Date dateMax = new Date();
          Date dateMin = new Date();
          try {
              dateMax = simpleDateFormat.parse("24:00");
  
              dateMin = simpleDateFormat.parse("00:00");
  
          } catch (Exception e) {
              e.printStackTrace();
          }
          difference = (dateMax.getTime() - startTime.getTime()) + (endTime.getTime() - dateMin.getTime());
      }
  
      String hour = String.format("%02d", TimeUnit.MILLISECONDS.toHours(difference));
      String inMins = String.format("%02d", TimeUnit.MILLISECONDS.toMinutes(difference) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(difference)));
      Log.d("lala", "onCreate: min" + hour + " " + inMins);
  
      if (hour.equalsIgnoreCase("00")) {
          if (inMins.equalsIgnoreCase("05")) {
                  Intent background = new Intent(context, AlarmServiceClass.class);
                  background.putExtra("time", programTime);
                  background.putExtra("id", id);
                  if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
                      context.startForegroundService(background);
                  } else {
                      context.startService(background);
                  }
          }
      }
  }
  }
  </code></pre>
  
  <p><em>AlarmServiceClass.java</em></p>
  
  <pre><code>public class AlarmServiceClass extends Service {
  
  long millis;
  int id;
  String programTime;
  Notification notification;
  NotificationManager notificationManager;
  IntentFilter intentFilter;
  
  
  @Override
  public void onCreate() {
      super.onCreate();
  
      Log.d("lala", "onCreate: ");
      notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  
      return START_STICKY;
  
  }
  
  private void showNotification(String programTime, int id) {
  
      RemoteViews views = new RemoteViews(getPackageName(), R.layout.notification);
  
      String CHANNEL_ID = "2018";
      CharSequence channelName = "Vinay";
  
      Intent recentIntent = new Intent(this, MainActivity.class);
      recentIntent.setAction("com.newitventure.remainder.STOP_SERVICE");
      recentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
      PendingIntent pendInt = PendingIntent.getActivity(this, id,
              recentIntent, PendingIntent.FLAG_ONE_SHOT);
  
      views.setTextViewText(R.id.text, programTime);
  
      notification = new NotificationCompat.Builder(this)
              .setCustomContentView(views)
              .setContentIntent(pendInt)
              .setAutoCancel(true)
              .setSmallIcon(R.drawable.ic_launcher_foreground)
              .setChannelId(CHANNEL_ID)
              .build();
  
  
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
          NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
                  channelName, NotificationManager.IMPORTANCE_LOW);
          channel.setSound(null, null); 
          notificationManager.createNotificationChannel(channel);
      }
  
      startForeground(id, notification);
    }
  }
  </code></pre>