The AlarmService is functioning properly. However, there is a problem.

Asked 1 years ago, Updated 1 years ago, 93 views

The AlarmService is functioning properly. However, there is a problem.

PendingIntent sender = PendingIntent.getBroadcast(LoginActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000, 60 * 1000, sender);

I have registered the alarm service as above and am using it.

Even after rebooting, it works properly, and after activities are ended, the alarm is confirmed to work properly while the cell phone is on.

However, when you turn off the screen for a long time or use the alarm service a lot, the alarm no longer rings.

The way I checked this is to set the time to register in Firebase every time the alarm goes off, but the value does not come in well at some point.

When I looked up the reason, I guessed that it is a phenomenon that occurs because it enters doz mode when it is not used for a long time in the marshmallow abnormal version.

For your information, targetsdkversion is 22.

I'd appreciate any help. Thank you.

alarmmanager alarm-service

2022-09-21 21:13

1 Answers

Added Dodge mode from marshmallow. There are several restrictions about alarms.

"The alarm scheduled for the AlarmManager class is disabled. The exception is the alarm set by the setAlarmClock() method and setAndAllowWhileIdle()."

The adb terminal allows the emulator to enter doz mode.

Try entering the emulator into Dodge mode in the same way as above and check the alarm.

To avoid this, you should write the code shown below. The example code I wrote is as follows.

 // After setting alarm manager, int, etc
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + intervalTime, repeatPendingIntent);
    } } else {
        alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + intervalTime, repeatPendingIntent);
    }

I don't use an alarm repeat, but I set one alarm unconditionally, and when the alarm goes off, I set "one alarm again" on the broadcast receiver.


2022-09-21 21:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.