I have the following code with two activities where I have a ListActivity in MainActivity then AddItemsActivity to dynamically add items to the ListActivity. I'm stuck on one part of it and I'm not sure if it is easier to fix the current code or if I should go about it a different way programmatically.

**My goal is when the data is sent from AddItemActivity to MainActivity a PendingIntent notification is generated which will fire off on the day selected.**

I have been searching Google and here at SO for about a week trying various proposed solutions and nothing seems to handle it how I need. 

I understand that I will eventually need some way to save the generated notifications in some storage format but for the moment I just want to verify the functionality works correctly.

MainActivity.java

```
public class MainActivity extends ListActivity {

    static final int ADD_ITEM_REQUEST = 1; // ActivityForResult request code

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ...
    } 

    // addItems is defined in XML Button onClick
    public void addItems(View view) {
        /* Start Activity For Result */
        Intent intent = new Intent(MainActivity.this, AddItemActivity.class);
        startActivityForResult(intent, ADD_ITEM_REQUEST);
    }

    // Activity Result passed from AddItemActivity
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request to respond to
    if (requestCode == ADD_ITEM_REQUEST) {
        // Make sure the result was successful
        if (resultCode == RESULT_OK) {
            if ((data.getExtras().containsKey("editTextView") && !data.getStringExtra("editTextView").isEmpty()) && data.getExtras().containsKey("textView") && !data.getStringExtra("textView").isEmpty()) {
                // HashMap defines and sets Intent extras to ListActivity items
                HashMap<String, String> temp = new HashMap<>();
                temp.put("editTextView", data.getStringExtra("editTextView"));
                temp.put("textView", data.getStringExtra("textView"));
                list.add(temp) // list is instance of ListAdapter

                ... // what (if anything) could go here?
            }
        } else {
            Toast.makeText(this, "An Error Has Occurred", Toast.LENGTH_SHORT).show();
        }
        adapter.notifyDataSetChanged(); // notifies ListAdapter of changes
    }
  }
}

```

AddItemActivity.java

```
public class AddItemActivity extends ActionBarActivity {

    EditText itemNameET;
    Button setDateBtn;
    TextView dateView;
    private Calendar calendar;
    private int year, month, day;

    private PendingIntent pendingIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_item);

        itemNameET = (EditText) findViewById(R.id.editItemText);
        setDateBtn = (Button) findViewById(R.id.setDateButton);

        dateView = (TextView) findViewById(R.id.setDateTextView);
        calendar = Calendar.getInstance();
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH);
        day = calendar.get(Calendar.DAY_OF_MONTH);
        showDate(year, month, day);
    }

    public void sendToListView(View view) {
        // Set result on AddItemActivity
        Intent resultIntent = new Intent();
        // Add extras or a data URI to this intent as appropriate.
        resultIntent.putExtra("editTextView", itemNameET.getText().toString()); // Item title
        resultIntent.putExtra("textView", dateView.getText().toString()); // Date
        resultIntent.putExtra("passDateYear", year); // Selected Year
        resultIntent.putExtra("passDateMonth", month); // Selected Month
        resultIntent.putExtra("passDateDay", day); // Selected Day

        Intent myIntent = new Intent(AddItemActivity.this, DateReceiver.class);
        pendingIntent = PendingIntent.getBroadcast(AddItemActivity.this, 0, myIntent, 0);
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
        alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + calendar.getTimeInMillis(), pendingIntent);
        // Toast.makeText(this, "New Item Added Successfully", Toast.LENGTH_LONG).show();
        Toast.makeText(this, "Date Passed: " + calendar.getTimeInMillis(), Toast.LENGTH_LONG).show();

        setResult(Activity.RESULT_OK, resultIntent);
        finish();
    }

    @SuppressWarnings("deprecation")
    public void setDate(View view) { // Button onClick action
        showDialog(999);
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        // TODO Auto-generated method stub
        if (id == 999) {
            return new DatePickerDialog(this, myDateListener, year, month, day);
        }
        return null;
    }

    private DatePickerDialog.OnDateSetListener myDateListener
        = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
            // arg1 = year
            // arg2 = month
            // arg3 = day
            showDate(arg1, arg2+1, arg3);
        }
    };

    private void showDate(int year, int month, int day) {
        dateView.setText(new StringBuilder().append(month).append("/").append(day).append("/").append(year));
    }
}

```

DateReceiver.java (BroadcastReceiver)

```
public class DateReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent service1 = new Intent(context, DateAlarmService.class);
        context.startService(service1);
    }
}

```

DateAlarmService (Service)

```
public class DateAlarmService extends Service {
    private NotificationManager notificationManager;

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @SuppressWarnings("static-access")
    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);

        notificationManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
    Intent intent1 = new Intent(this.getApplicationContext(), MainActivity.class);

    Notification notification = new Notification(R.mipmap.ic_launcher, "Test!", System.currentTimeMillis());
    intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notification.setLatestEventInfo(this.getApplicationContext(), "Test", "Test!", pendingNotificationIntent);
    notification.defaults |= Notification.DEFAULT_SOUND; // notification sound
    notification.defaults |= Notification.DEFAULT_LIGHTS; // notification lights
    notification.defaults |= Notification.DEFAULT_VIBRATE; // notification vibration

    notificationManager.notify(0, notification);
}

```

The code provided creates a notification as soon as onActivityResult begins even if I set the calendar date for one or more days ahead.