JobRescheduleService incorrectly reschedules my job
See original GitHub issueHello guys,
Your library is helping me a lot and you have my sincerest appreciation for your work. However, I think I have stumbled upon a bug.
The way I’m using the library is similar to a calendar type app. I am scheduling exact type jobs. When a job runs I schedule another job for tomorrow at the exact same time or next week at the exact same day and time.
I think I have found an issue where the JobRescheduleService class will incorrectly reschedule one of my jobs. It basically reschedules the job for right now without a delay, when initially it was scheduled with a 24 hour delay.
I have prepared a detailed log together with explanations of what the app is doing at every point in the log and in what state the app is.
I have managed to reproduce the issue with the exact steps below on Android versions 6.0 & 7.1.1. Whatever else information I should provide please let me know.
//Open app, schedule a job in a few seconds
D/JobProxy14: Scheduled alarm, request{id=1, tag=activity:55f8b160dba84c2e86759bf384d0a118}, delay 00:00:26, exact true, reschedule count 0
//Close app completely (swipe off app in recent apps)
//Job time comes and it starts
08-09 17:53:00.581 9635-9667/? D/JobRescheduleService: Reschedule service started
08-09 17:53:00.585 9635-9668/? D/PlatformAlarmService: Run job, request{id=1, tag=activity:55f8b160dba84c2e86759bf384d0a118}, waited 00:00:26, delay 00:00:26
08-09 17:53:00.590 9635-9668/? I/JobExecutor: Executing request{id=1, tag=activity:55f8b160dba84c2e86759bf384d0a118}, context PlatformAlarmService
//Job runs. My job does 2 things. Fires up a notification (opening the app process). And schedules another job with a delay of 24 hours (Tomorrow at the same time)
//If you're wondering why I'm not using a periodic job, it's because I need daily and weekly reminders at the exact same time.
08-09 17:53:00.632 9635-9669/? D/JobProxy14: Scheduled alarm, request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118}, delay 23:59:59, exact true, reschedule count 0
08-09 17:53:00.632 9635-9669/? I/JobExecutor: Finished job{id=1, finished=true, result=SUCCESS, canceled=false, periodic=false, class=ReminderJob, tag=activity:55f8b160dba84c2e86759bf384d0a118}
08-09 17:53:00.635 9635-9668/? D/PlatformAlarmService: Finished job, request{id=1, tag=activity:55f8b160dba84c2e86759bf384d0a118} SUCCESS
//at this point the Job ran, displayed the notification and correctly scheduled the next job for tomorrow (id = 2)
//I tap on the notification which opens the app (the app was completely closed) and then I immediately background the app.
09 17:53:10.616 9635-9667/? I/JobManager: Found pending job request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118}, canceling
08-09 17:53:10.628 9635-9667/? D/JobProxy14: Scheduled alarm, request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118}, delay 00:00:00, exact true, reschedule count 0
08-09 17:53:10.628 9635-9667/? D/JobRescheduleService: Reschedule 1 jobs of 1 jobs
08-09 17:53:10.932 9635-9856/? D/PlatformAlarmService: Run job, request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118}, waited 00:00:00, delay 00:00:00
08-09 17:53:10.940 9635-9856/io.healthsteps.healthsteps I/JobExecutor: Executing request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118}, context PlatformAlarmService
//Since the app has just been started (by way of the notification) it looks like your *JobRescheduleService* runs at app start and is cleaning up all the jobs and reschedules them or something.
//The problem is that the job I scheduled above for tomorrow is cancelled and is incorrectly rescheduled for right now, without a delay.
//And immediately, it runs:
08-09 17:53:10.984 9635-9669/? D/JobProxy14: Scheduled alarm, request{id=3, tag=activity:55f8b160dba84c2e86759bf384d0a118}, delay 23:59:49 (+1 day), exact true, reschedule count 0
08-09 17:53:10.985 9635-9669/? I/JobExecutor: Finished job{id=2, finished=true, result=SUCCESS, canceled=false, periodic=false, class=ReminderJob, tag=activity:55f8b160dba84c2e86759bf384d0a118}
08-09 17:53:10.989 9635-9856/? D/PlatformAlarmService: Finished job, request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118} SUCCESS
I can reproduce this issue 100% of the time provided I follow the exact steps above. The app must be closed off after the first job is scheduled. The app must be opened when the job runs and then it must be backgrounded (paused). These last last 2 steps must be done before the JobRescheduleService starts doing its thing.
I forgot to mention, this is how I’m scheduling the jobs:
new JobRequest.Builder(repeatingReminder.getActivityID())
.setExact(timeToFireIn)
.setExtras(extras)
.setPersisted(true)
.build()
.schedule();
Issue Analytics
- State:
- Created 6 years ago
- Comments:15
Top GitHub Comments
@AndreiHarasemiuc @dshatz I’m pretty confident that I found the cause for the bug. Thanks for your patience! Could you give version
1.2.0-RC2
a try? This one includes the fix.@Abdullah-Hussein https://developer.android.com/reference/android/app/AlarmManager.html#set(int, long, android.app.PendingIntent) Please don’t post in this issue anymore. If you still have questions, create another issue. Your “problem” is expected behavior and working properly.