Skip to content Skip to sidebar Skip to footer

Why Repeatingalarm Only Runs For 1 Time Only

I am working on repeating alarm . problem is that my repeat alarm only runs for one time only on set time but not repeat on that time next day. If it is 5/28/2015 and time is 1:40P

Solution 1:

call at every day at night : 12 AM

CalendarcurrentCalendar= Calendar.getInstance();
    CalendartodaysCalendar= Calendar.getInstance();
    todaysCalendar.setTime(getDate());
    CalendarnextDayCalandar= Calendar.getInstance();
    nextDayCalandar.setTimeInMillis(todaysCalendar.getTimeInMillis()
            + (3600000 * 24));

    longtime= Calendar.getInstance().getTimeInMillis()
            + (nextDayCalandar.getTimeInMillis() - currentCalendar.getTimeInMillis());

    IntentmyIntent=newIntent(HomeActivity.this, MyReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(HomeActivity.this, 0, myIntent, 0);

    AlarmManageralarmManager= (AlarmManager) getSystemService(ALARM_SERVICE);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
    {
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 3600000 * 24, pendingIntent);
    }
    else
    {
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, time, 3600000 * 24, pendingIntent);
    }

supportive method

@SuppressLint("SimpleDateFormat")
privateDategetDate()
{
    SimpleDateFormat format = newSimpleDateFormat("dd-MM-yyyy");
    try
    {
        return format.parse(format.format(newDate()));
    }
    catch (ParseException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    returnnewDate();
}

Post a Comment for "Why Repeatingalarm Only Runs For 1 Time Only"