Simple Reminder Notification in Android
<p>I’m developing a simple reminders list for android. when the user presses a reminder from the list, he gets title, description, date and time showing up, things he inputed when he first created the reminder. Then, i’m setting up an alarmManager and broadcastReceiver to show reminder notification based on given time and date. </p>

<p>My problem is with the notifications. When the user presses the notification he should go to the that specific reminder screen. It works for the first reminder only, and the problem is when ever the user creates a second reminder, the pendingIntent of the notification shows only the screen of the first reminder.</p>

<p>I’m having the following classes:</p>

<p>MainListActivity : to show the created list of reminders.
EditActivity: to allow the user input new reminder or edit an existing one.
ItemViewActivity: to show a specific reminder screen after being clicked from the list.
NotifyReceiver: it is a broadcastReceiver class.
ContentProvider and databaseAdapter classes</p>

<p>Here is part of EditActivity where I create alarmManager and set the pendingIntent to the broadcastReceiver and pass it a bundle of user entries:</p>

<pre><code>Bundle bundle = new Bundle();

    bundle.putString(ToDoDatabaseAdapter.KEY_TITLE, titleText.getText().toString());
    bundle.putString(ToDoDatabaseAdapter.KEY_DATE, dateString);
    bundle.putString(ToDoDatabaseAdapter.KEY_BODY, bodyText.getText().toString());
    bundle.putString(ToDoDatabaseAdapter.KEY_TIME, timeString);

    if (RowId != 0) {
        bundle.putLong(ToDoDatabaseAdapter.KEY_ROWID, RowId);
    }
Intent notify = new Intent(this, Notify.class);
    notify.putExtras(bundle);



PendingIntent contentIntent = PendingIntent.getBroadcast(this, 0, notify, 0);

                Calendar cal = Calendar.getInstance();
                cal.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
                cal.set(Calendar.MONTH, datePicker.getMonth());
                cal.set(Calendar.YEAR, datePicker.getYear());
                //cal.set(Calendar.HOUR, timePicker.getCurrentHour());
                cal.set(Calendar.MINUTE, timePicker.getCurrentMinute());
                cal.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour());
                cal.set(Calendar.SECOND, 0);

                long when = cal.getTimeInMillis();



                AlarmManager alm=(AlarmManager)getSystemService(ALARM_SERVICE);
                alm.set(AlarmManager.RTC_WAKEUP, when, contentIntent );     
</code></pre>

<p>Here is my broadcastReceiver class:</p>

<pre><code>@Override
    public void onReceive(Context context, Intent intent) {

        Intent viewIntent = new Intent(context, ItemView.class);
    Bundle bundle = intent.getExtras();

    viewIntent.putExtras(bundle);

    // To get notification alert on the top bar when we press start button:
            int icon = R.drawable.ic_launcher;
            CharSequence tickerText = "Reminder is due";
            long when = System.currentTimeMillis();
            Notification notification = new Notification(icon, tickerText, when);

// this is what we get on the list after pulling down notification window.

            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, viewIntent, 0);
            CharSequence contentTitle = bundle.getString(ToDoDatabaseAdapter.KEY_TITLE);
            CharSequence contentText = bundle.getString(ToDoDatabaseAdapter.KEY_DATE);

            notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

      NotificationManager nm = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
            nm.notify(SERV_DEMO_ID, notification);

            Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            long pattern[] = new long[] {0,200,100,200};
            vibrator.vibrate(pattern,-1);

    }
</code></pre>

<p>I played with onResume(), onStart(), onPause(), onStop() methods with no success.  </p>

<p>Appreciate any suggestions. Thank you</p>
