Skip to content Skip to sidebar Skip to footer

Alarmmanager Running At The Wrong Time

I am trying to put an AlarmManager to run every 3 min but it is running at wrong and varied times, moments in seconds and others does not run. I am trying to test on an Android 7.0

Solution 1:

Use setExactAndAllowWhileIdle(int type, long triggerAtMillis, PendingIntent operation) instead. It helps to wakeup your device.

EDIT

 int currentapiVersion = android.os.Build.VERSION.SDK_INT;
        if (currentapiVersion < android.os.Build.VERSION_CODES.KITKAT){
            am.set(AlarmManager.RTC_WAKEUP, nexttime, pi);
        } else {
            if (currentapiVersion < android.os.Build.VERSION_CODES.M) {
                am.setExact(AlarmManager.RTC_WAKEUP, nexttime, pi);
            } else {
                    am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nexttime, pi);
            }
        }

Post a Comment for "Alarmmanager Running At The Wrong Time"