Here is my class which launches and sets an alarm when the phone is rebooted.

```
public class NotifStart extends BroadcastReceiver
{

private static AlarmNotif reAlarm = new AlarmNotif();

@Override
public void onReceive(Context context, Intent intent)
{

    if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
    {
        reAlarm.SetAlarm(context.getApplicationContext());

    }
}

}

```

and here's my alarm's receiver class:

```
public class AlarmNotifReceiver extends BroadcastReceiver {

PendingIntent pi;

@Override
public void onReceive(Context context, Intent intent)
{
//stuff
}

public void SetAlarm(Context context)
{
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, AlarmNotifReceiver.class);
    pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 10*1000, pi); // Millisec * Second
}

public void CancelAlarm(Context context)
{
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pi);
}

}

```

Now, if I use `SetAlarm()` as the phone is open I am able to use `CancelAlarm()` and actually cancel it. But whenever I reboot the phone and set the alarm by using the above class `NotifStart` I am unable to cancel it. I tried to use the cancel method from within the `NotifStart` but since I can't really give the context of a non-activity class as `onReceive` it just doesn't work.