Hello,

I create a jobscheduler in onReceive method of boot complete receiver. The
job is not scheduled to run after two minutes. The device is in idle and
wi-fi connected.

Can anyone give help?

Thanks,

James

public void onReceive(Context context, Intent intent) {

    JobScheduler tm =
            (JobScheduler)
context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    tm.cancel(JOB_ID);

    JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, new
ComponentName(context, TestService.class));
    builder.setPeriodic(TWO_MINUTES);
    builder.setPersisted(true);
    builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
    builder.setRequiresDeviceIdle(true);

    tm.schedule(builder.build());
}

then in the TestService


@Override
public boolean onStartJob(final JobParameters params) {

    Log.i(LOG_TAG, "job started");

    new Thread(new Runnable() {
        @Override
        public void run() {
            //do something here, then call jobFinished
            jobFinished(params, true);
        }
    }).start();

    return true;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/CAMhUYgyqqBqBsqpwo%2BqYm%3DEdF_Ff-e1_q1%3D%2B-32X_5uU8PvY4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to