0

I am developing an app that uses the JobScheduler API introduced in Android 5.0. I schedule jobs and log when they are executed. This work well on my test devices except on the HTC One running Anroid 5.0.2.

The HTC device does not consider the constraints at all. I use setMinimumLatency and setOverrideDeadline but jobs are being executed hours after their deadline. Most recently I could observe that jobs that were scheduled at different times were all flushed at once, many hours too late.

Can somebody explain this to me please? I really don't get it. These are the fundamentals of this API which is (afaik) not in the hands of the device manufacturer to be modified. Is this problem specific to the Android version? (I have yet to test it on more devices)


While this is not a code related question, because it works as expected on most devices, I'll post it anyway. This is how I schedule jobs:

    mJobScheduler = (JobScheduler) MainApplication.get().getSystemService(Context.JOB_SCHEDULER_SERVICE);
    mJobScheduler.cancelAll();

    JobInfo.Builder builder = new JobInfo.Builder(StateFeedbackJobService.JOB_ID,
                new ComponentName(MainApplication.get(), StateFeedbackJobService.class.getName()));

    builder.setMinimumLatency(Config.NOTIFICATION_DELAY_MIN);
    builder.setOverrideDeadline(Config.NOTIFICATION_DELAY_MAX);

    if (mJobScheduler.schedule(builder.build()) <= 0) {
        // error
    } else {
        // success
    }

and this is the implementation of a job

public class StateFeedbackJobService extends JobService {
    public static final int JOB_ID = 2;
    private JobScheduler mJobScheduler;

    public StateFeedbackJobService() {
        mJobScheduler = (JobScheduler) MainApplication.get().getSystemService(Context.JOB_SCHEDULER_SERVICE);
    }

    private Handler mJobHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            // do some work
            jobFinished((JobParameters) msg.obj, false);
            return true;
        }
    });

    @Override
    public boolean onStartJob(JobParameters params) {
        // job started
        mJobHandler.sendMessage(Message.obtain(mJobHandler, 1, params));
        return true;
    }

    @Override
    public boolean onStopJob(JobParameters params) {
        // job stopped
        mJobHandler.removeMessages(1);
        return false;
    }
}
Alex
  • 1,395
  • 1
  • 13
  • 22

0 Answers0