Code example for AlarmManager

Methods: setInexactRepeating

0
    	AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    	Calendar calendar = Calendar.getInstance();
    	calendar.setTimeInMillis(System.currentTimeMillis());
    	calendar.add(Calendar.MINUTE, 10);
    	Log.d(TAG, "Setting alarm");
    	alarmManager.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), interval, pendingIntent);
    } 
    public void onDisabled(Context context) {
    	// We need to check if there are any widgets of other sizes still on the screen. 
        AppWidgetManager manager = AppWidgetManager.getInstance(context);
        boolean cancelAlarm = true;
        // 1x2 
        ComponentName provider = new ComponentName(context, PhoneBalanceWidget.class);
	    if(manager.getAppWidgetIds(provider).length > 0) {
	    	cancelAlarm = false;
	    } 
        // 2x2 
        provider = new ComponentName(context, WidgetProvider2x2.class);
	    if(manager.getAppWidgetIds(provider).length > 0) {
	    	cancelAlarm = false;
	    }