Dusan Dimitrijevic
Dusan Dimitrijevic

Reputation: 3219

How would i set repeat reminder interval until some date in android?

I have done some research on this, but i'm still confused how would i do this in a way i want. This library i'm using for Recurrence Picker and now how to make this to work with my code where i'm setting a date of birthday. I want to allow user to chose repeat time until that date.

Here is my code:

private void setDateTimeField () {
    final Calendar newCalendar = Calendar.getInstance();
    mDatePickerDialog = new DatePickerDialog(AddBirthday.this, new OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar newDate = Calendar.getInstance();
            newDate.set(year, monthOfYear, dayOfMonth);
            mYear = c.get(Calendar.YEAR);
            getAge = mYear - year;
            if (getAge == 0) {
                SuperActivityToast.create(AddBirthday.this, "Invalid Date of Birthday!",
                        SuperToast.Duration.SHORT, Style.getStyle(Style.RED, SuperToast.Animations.FLYIN)).show();

            } else {
                addBirthdayDate.setText(dateFormatter.format(newDate.getTime()));
                dateSelected = String.valueOf(dayOfMonth) + " /" + String.valueOf(monthOfYear + 1)
                        + " /" + String.valueOf(year);
            }
            SuperActivityToast.create(AddBirthday.this, "Notification set for: " + dayOfMonth + "/"
                    + (monthOfYear + 1) + "/" + year, SuperToast.Duration.SHORT, Style.getStyle(Style.RED, SuperToast.Animations.FLYIN))
                    .show();
        }
    }, newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
}

Upvotes: 1

Views: 223

Answers (1)

McflyDroid
McflyDroid

Reputation: 177

The Best choice would be to use a service, inside you setup a code like this :

 alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
 Date date= new Date();
 long timer = date.getTime()+inactivityTimer;
 Intent intentAlarm = new Intent(ACTION );
 alarmManager.set(
                    AlarmManager. RTC_WAKEUP,
                    timer,
                    PendingIntent. getBroadcast(context ,1,  intentAlarm , PendingIntent.FLAG_UPDATE_CURRENT ));

Change this to trigger to your date. Make the intent trigger to your action (birthday notification for your case... )

If you got any question.

Upvotes: 1

Related Questions