Q:

How do I repeat an Alarm in Android?

I need to Repeat the Alarm everyday . And this is how I trigger an Alarm single time.
public void clicker (View view)
{

    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);
    TimePickerDialog mTimePicker;
    mTimePicker = new TimePickerDialog(AddAlarm.this,new TimePickerDialog.OnTimeSetListener()
    {
                @Override
                public void onTimeSet(TimePicker timePicker,
                                      int selectedHour, int selectedMinute)
                {

                    calendar.set(Calendar.HOUR_OF_DAY, selectedHour);
                    calendar.set(Calendar.MINUTE, selectedMinute);

                    int c_hour,c_min;
                    String format;
                    c_hour=selectedHour;
                    c_min=selectedMinute;

                    if (c_hour == 0) {
                        c_hour += 12;
                        format = "AM";
                    } else if (c_hour == 12) {
                        format = "PM";
                    } else if (c_hour > 12) {
                        c_hour -= 12;
                        format = "PM";
                    } else {
                        format = "AM";
                    }

                    String formatTime = String.format("%02d : %02d %s", c_hour, c_min, format);

                    TextView dimple = (TextView)findViewById(R.id.timeText);
                    dimple.setText(formatTime);
                    setAlarm(calendar);

                }

    }, hour, minute, false);
    mTimePicker.setTitle("Select Time");
    mTimePicker.show();

}

private void setAlarm(Calendar targetCal)
{
    Intent alarmintent = new Intent(AddAlarm.this, AlarmReceiver.class);
    alarmintent.putExtra("ALARM_NO", tempx);
    alarmintent.setAction("my.action.string");
    PendingIntent sender = PendingIntent.getBroadcast(AddAlarm.this, pen, alarmintent, PendingIntent.FLAG_ONE_SHOT);

    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    alarmManager.setExact(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), sender);

}

Now how should I change my code to trigger the alarm repeatedly everyday? And how can I kill the Alarm as well? Thanks , 

A:

Use AlarmManager.setRepeating() method instead of AlarmManager.setExact().
eg:
 // Set the alarm to start at 8:30 a.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 30);

// setRepeating() lets you specify a precise custom interval--in this case,
// 20 minutes.
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
        1000 * 60 * 20, alarmIntent);

Here you can find more details for how to schedule a repeating alarm and how to cancel it.

