0

when i use only seconds method its working like objCalendar.add(Calendar.SECOND, 30); but not working date and time

Code in activity:

      Calendar objCalendar = Calendar.getInstance();


    objCalendar.setTimeInMillis(System.currentTimeMillis());
    objCalendar.set(Calendar.MONTH, Calendar.APRIL);
    objCalendar.set(Calendar.DATE, 19);

    objCalendar.set(Calendar.HOUR_OF_DAY, 11);
    objCalendar.set(Calendar.MINUTE, 44);
    objCalendar.set(Calendar.SECOND, 00);
    objCalendar.set(Calendar.MILLISECOND, 0);        

    Intent intent = new Intent(this, MyBroadCastClass.class);


    PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
            192837, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

    long time24h = 24 * 60 * 60 * 1000;
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, objCalendar.getTimeInMillis(), 1000, pendingIntent);


    Toast.makeText(this, "Activity File", Toast.LENGTH_LONG).show();
  • Possible duplicate of [Android Alarm Manager not working with specific date and time](https://stackoverflow.com/questions/51324536/android-alarm-manager-not-working-with-specific-date-and-time) – Sandeep Malik Apr 18 '19 at 14:53
  • 1
    I tried that also but it's still not working. I'm using android version 6.0.1 (Marshmello) – Akshay Rasalkar Apr 18 '19 at 14:59
  • `objCalendar.set(Calendar.MONTH, 5);` – That's June. Is that what you meant? Also, why are you calling `clear()` there? Debugging attempt? – Mike M. Apr 18 '19 at 23:18
  • I have fixed problem from the following line and thanks for reply:) objCalendar.setTimeInMillis(System.currentTimeMillis()); – Akshay Rasalkar Apr 20 '19 at 14:04
  • That line – `objCalendar.setTimeInMillis(System.currentTimeMillis());` – is unnecessary. `Calendar.getInstance()` returns an instance with the current time already set. Your problem was most likely just the wrong month. – Mike M. Apr 20 '19 at 14:26

0 Answers0