Android jobScheduler不会因为jobFinished而停止(params,false) [英] Android jobScheduler won't stop with jobFinished(params, false)

查看:112
本文介绍了Android jobScheduler不会因为jobFinished而停止(params,false)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个jobService.这是onStartJob()的样子.

I'm tring to create a jobService. Here is what onStartJob() looks like.

@Override
public boolean onStartJob(JobParameters params) {
    Log.d(TAG, "onStartJob");
    Log.d(TAG, "Params= " + params.getJobId());
    param = params;
    jobFinished(params, false);
    //startAsync();
    return true;
}


@Override
public boolean onStopJob(JobParameters params) {
     Log.d(TAG, "onStopJob");
    return false;
}

这是应该开始工作的代码.

Here is the code that is supposed to start the job.

public void startJobScheduler(){
    Log.d(TAG, "inside startJobScheduler");
    Activity activity = this.cordova.getActivity();
    Context context = activity.getApplicationContext();


     mJobScheduler = (JobScheduler)context.getSystemService(Context.JOB_SCHEDULER_SERVICE );
     JobInfo.Builder job = new JobInfo.Builder(111, new ComponentName(context, JobSchedulerService.class));

     job.setPeriodic(60000);
     Log.d(TAG, "before mJobScheduler.schedule(job.build())");
     if( mJobScheduler.schedule( job.build() ) <= 0 ) {
         Log.d(TAG, "job schedule failed");
     }
    Log.d(TAG, "333");
}

我无法阻止它.它只会每1-5分钟发射一次.我在onStartJob()中放置了jobFinished(params,false)并注释掉了该任务,试图在启动后立即将其杀死,但是它一直在触发.似乎jobFinished()触发了onDestroy()并触发了我的服务被销毁的事情,但是随后另一个作业使用了相同的ID并开始将其全部备份.

I can not get it to stop. It just keeps firing every 1-5 mins. I put jobFinished(params, false) in onStartJob() and commented out the task to try to kill it off right after it starts, but it just keeps firing. It seems jobFinished() fires something, as onDestroy() is called and my service gets destroyed, but then another job comes in with the same ID and starts it all back up.

我像每个示例所示,在清单中都有BIND_JOB_SERVICE.

I have BIND_JOB_SERVICE in the manifest like every example shows.

关于jobFinished(params,false)为什么没有杀死setPeriodic(60000)的任何想法?

Any ideas on why jobFinished(params, false) doesn't seem to kill the setPeriodic(60000)?

推荐答案

好吧,我想出了是否有人遇到这个问题.

Well I figured it out if anyone else has this problem.

jobFinished()不会停止您设置的定期时间.它只是告诉作业您已经完成,可以释放唤醒锁,因此Android不必强制终止作业.

jobFinished() won't stop the periodic time you set from continuing. It just tells the job that you are finished, to release the wakelock, so Android doesn't have to kill the job off forcefully.

我要做的是在我的服务中重新创建jobScheduler并调用cancelAll().您显然也可以调用cancel(job_id).

What I had to do was recreate the jobScheduler in my service and call cancelAll(). You could also apparently call cancel(job_id).

jobScheduler = (JobScheduler)this.getSystemService(Context.JOB_SCHEDULER_SERVICE );
jobScheduler.cancelAll();

这篇关于Android jobScheduler不会因为jobFinished而停止(params,false)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆