title: Updating notifications after being added
body: <p>I want to update the content for a reminder after it has been added before being received by the user. After setting a reminder through AlarmManager using the data stored in sqlite database, the notification from the reminder set only shows the data, title and description, that was first added, not any updated data stored corresponding to the ID as primary key.</p>
  <p>Things I have tried:</p>
  <ul>
  <li>cancelling the pending intent for the reminder then setting it again after updating the data stored in the database but it still displays the same result.</li>
  <li>using an activity for adding data to be stored in the database to set a reminder and using another activity for updating this data as an attempt to update the reminder content with the same ID issued. One result shows two notifications received, one with initial title and description, and the other with updated information.</li>
  </ul>
  <p>Currently, the methods I use to set and cancel a reminder is in my Adapter class for Recyclerview. I am stuck on updating although adding and cancel works fine.</p>
  <p>Update: Now I use two separate activities for the add and update reminder functions.</p>
  <p>For adding a reminder:</p>
  <pre><code>databaseManager.addReminder(titlePicked, descriptionPicked, timePicked, datePicked, dateTimePicked);
  startActivity(new Intent(getApplicationContext(), MainActivity.class));
  setAlarm();
  
  private void setAlarm() {
          AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  
          Intent intent = new Intent(getApplicationContext(), ReminderReceiver.class);
          intent.putExtra(&quot;DateTime&quot;, dateTimePicked);
          intent.putExtra(&quot;NotifID&quot;, remId);
          intent.putExtra(&quot;Title&quot;, titlePicked);
          intent.putExtra(&quot;Description&quot;, descriptionPicked);
  
          PendingIntent addIntent = PendingIntent.getBroadcast(this, remId, intent, 0);
          alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, Date.parse(dateTimePicked), addIntent);
      }
  </code></pre>
  <p>For updating a reminder:</p>
  <pre><code>databaseManager.updateReminder(remindId, titlePicked2, descriptionPicked2, timePicked, datePicked, dateTimePicked);
  startActivity(new Intent(getApplicationContext(), MainActivity.class));
  updateAlarm();
  
  private void updateAlarm() {
          AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  
          Intent intent = new Intent(getApplicationContext(), ReminderReceiver.class);
          intent.putExtra(&quot;DateTime&quot;, dateTimePicked);
          intent.putExtra(&quot;NotifID&quot;, remindId);
          intent.putExtra(&quot;Title&quot;, titlePicked2);
          intent.putExtra(&quot;Description&quot;, descriptionPicked2);
  
          PendingIntent updateIntent = PendingIntent.getBroadcast(this, remindId, intent, 0);
          alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, Date.parse(dateTimePicked), updateIntent);
      }
  </code></pre>
  <p>Receiver class:</p>
  <pre><code>public class ReminderReceiver extends BroadcastReceiver {
  
  private static final String CHANNEL_ID = &quot;CHANNEL_REMIND&quot;;
  String DateTimeChoice, TitleChoice, DescriptionChoice;
  int notificationID;
  
  @Override
  public void onReceive(Context context, Intent intent) {
      DateTimeChoice = intent.getStringExtra(&quot;DateTime&quot;);
      notificationID = intent.getIntExtra(&quot;NotifID&quot;, 0);
      TitleChoice = intent.getStringExtra(&quot;Title&quot;);
      DescriptionChoice = intent.getStringExtra(&quot;Description&quot;);
  
      Intent mainIntent = new Intent(context, ViewReminder.class);
      mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
  
      PendingIntent contentIntent = PendingIntent.getActivity(context, notificationID, mainIntent, 0);
      NotificationManager notificationManager =
              (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
          // For API 26 and above
          CharSequence channelName = &quot;My Notification&quot;;
          int importance = NotificationManager.IMPORTANCE_DEFAULT;
  
          NotificationChannel channel = new NotificationChannel(CHANNEL_ID, channelName, importance);
          notificationManager.createNotificationChannel(channel);
      }
  
      NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
              .setSmallIcon(android.R.drawable.ic_dialog_info)
              .setContentTitle(TitleChoice)
              .setContentText(DescriptionChoice)
              .setContentIntent(contentIntent)
              .setPriority(NotificationCompat.PRIORITY_DEFAULT)
              .setColor(context.getResources().getColor(R.color.purple_700))
              .setAutoCancel(true);
  
      notificationManager.notify(notificationID, builder.build());
  }
  </code></pre>
  <p>Adapter class:</p>
  <pre><code>int remindId = reminder.getReminderId();
  databaseManager = new DatabaseManager(holder.view.getContext());
  sqLiteDB = databaseManager.getWritableDatabase();
  
  public void onClick(View view) {
                  Reminder reminder = remindList.get(holder.getAdapterPosition());
                  PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
                  popupMenu.setGravity(Gravity.END);
                  popupMenu.getMenu().add(&quot;Edit&quot;).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                      @Override
                      public boolean onMenuItemClick(MenuItem menuItem) {
                          Intent intent = new Intent(view.getContext(), UpdateReminderActivity.class);
                          intent.putExtra(&quot;reminderId&quot;, remindId);
                          intent.putExtra(&quot;title&quot;, reminder.getReminderTitle());
                          intent.putExtra(&quot;definition&quot;, reminder.getReminderDefinition());
                          view.getContext().startActivity(intent);
                          return true;
                      }
                  });
  </code></pre>