android 牛轧糖中的作业调度程序不是 运行
Job scheduler in android nougat is not running
我试图让作业调度程序每 3 秒后运行一次 运行,但它在 android noughat 上不起作用。这是我的代码。
mJobScheduler = (JobScheduler) getSystemService( Context.JOB_SCHEDULER_SERVICE );
JobInfo.Builder builder = new JobInfo.Builder( 1,
new ComponentName( getPackageName(), JobSchedulerService.class.getName() ) );
builder.setPeriodic(3000);
builder.setRequiresDeviceIdle(false);
builder.setPersisted(true);
JobInfo j=builder.build();
mJobScheduler.schedule(j);
包含要在作业上执行的代码的作业计划服务。
public class JobSchedulerService extends JobService {
private Handler mJobHandler = new Handler( new Handler.Callback() {
@Override
public boolean handleMessage( Message msg ) {
Toast.makeText( getApplicationContext(), "JobService task running", Toast.LENGTH_SHORT ).show();
jobFinished( (JobParameters) msg.obj, false );
return true;
}
} );
@Override
public boolean onStartJob(JobParameters params ) {
// Toast.makeText( getApplicationContext(), "kutta", Toast.LENGTH_SHORT ).show();
mJobHandler.sendMessage( Message.obtain( mJobHandler, 1, params ) );
return true;
}
@Override
public boolean onStopJob( JobParameters params ) {
mJobHandler.removeMessages( 1 );
return false;
}
}
作业可以安排的最短时间为 15 分钟。这始于牛轧糖。如果将其设置为小于 15 分钟的值,则作业将使用 15 分钟。
getMinPeriodMillis()复制粘贴下面的功能描述
Query the minimum interval allowed for periodic scheduled jobs. Attempting to declare a smaller period that this when scheduling a job will result in a job that is still periodic, but will run with this effective period.
我试图让作业调度程序每 3 秒后运行一次 运行,但它在 android noughat 上不起作用。这是我的代码。
mJobScheduler = (JobScheduler) getSystemService( Context.JOB_SCHEDULER_SERVICE );
JobInfo.Builder builder = new JobInfo.Builder( 1,
new ComponentName( getPackageName(), JobSchedulerService.class.getName() ) );
builder.setPeriodic(3000);
builder.setRequiresDeviceIdle(false);
builder.setPersisted(true);
JobInfo j=builder.build();
mJobScheduler.schedule(j);
包含要在作业上执行的代码的作业计划服务。
public class JobSchedulerService extends JobService {
private Handler mJobHandler = new Handler( new Handler.Callback() {
@Override
public boolean handleMessage( Message msg ) {
Toast.makeText( getApplicationContext(), "JobService task running", Toast.LENGTH_SHORT ).show();
jobFinished( (JobParameters) msg.obj, false );
return true;
}
} );
@Override
public boolean onStartJob(JobParameters params ) {
// Toast.makeText( getApplicationContext(), "kutta", Toast.LENGTH_SHORT ).show();
mJobHandler.sendMessage( Message.obtain( mJobHandler, 1, params ) );
return true;
}
@Override
public boolean onStopJob( JobParameters params ) {
mJobHandler.removeMessages( 1 );
return false;
}
}
作业可以安排的最短时间为 15 分钟。这始于牛轧糖。如果将其设置为小于 15 分钟的值,则作业将使用 15 分钟。
getMinPeriodMillis()复制粘贴下面的功能描述
Query the minimum interval allowed for periodic scheduled jobs. Attempting to declare a smaller period that this when scheduling a job will result in a job that is still periodic, but will run with this effective period.