I am trying to create a jobService. This 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 should run the task.
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"); }
I can not make him stop. He just shoots every 1-5 minutes. I put jobFinished (params, false) in onStartJob () and commented on the task to try to kill it right after it starts, but it just keeps shooting. It seems that jobFinished () is starting something, since onDestroy () is being called, and my service is being destroyed, but then another job comes up with the same id and starts all its backups.
I have BIND_JOB_SERVICE in the manifest, as shown in each example.
Any ideas on why jobFinished (params, false) doesn't seem to kill setPeriodic (60000)?
source share