yigit / android-priority-jobqueue

A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.
3.4k stars 395 forks source link

Persistent jobs not run after device loses power #439

Open xTheITx opened 6 years ago

xTheITx commented 6 years ago

I've come across an issue where jobs aren't always run after a device is restarted due to a forced shutdown. I've not been able to reproduce the issue if I shut down the device normally, only if I force restart it (eg. by holding down the power button for 10 seconds).

I have added an example project, but really all that's required is that the some (3 to 6+) persistent jobs be added to the queue, then the device be force shut down. Upon re-entering the app, the jobs are usually not run. Adding subsequent jobs will result in the job completing successfully. Force closing the app or shutting down the device correctly doesn't appear to trigger the bug.

Attached in the zip file are also logs (job_queue_logs.txt) which show the logcat debug output of the app after it's restarted. In the logs is clearly shows that there are 6 jobs remaining, but in this case only the first job was run.

Interestingly, if a call to JobManager.count() is made just after the JobManager is instantiated, the jobs will usually complete successfully. In the example project, there is an AsyncTask that can be uncommented to show this behaviour.

Clear steps to reproduce: 1) Install app (Tested on Android 4.4, 6.0 and 7.0 tablets and phones, not tested on emulator) 2) Add several jobs to the queue (3 to 6), several jobs may not be necessary but it makes things easier to test and verify the issue 3) Force restart the device by holding down the power button (may differ per device) 4) Power on device 5) Re-launch app 6) Notice none or not all the jobs are executed

https://drive.google.com/file/d/1gwKrGFoCg7I7Xf2Yx56PEtt5tujYJn5F/view?usp=sharing

I'll continue to investigate the debug logs and source code, but I would appreciate any assistance in figuring out what the issue is.

Thank you very much for your time.