0

Hi Android geeks over there,

I am developing an application which uses 'com.firebase:firebase-jobdispatcher:0.8.5' to schedule jobs. But the jobs are not getting executed in the tested device.

While I checked the dumpsys activity service GcmService I got the following log, in which my job is marked as Not yet run.

What would be the possible reason for this behavior? I also found a status like READY_BATTERY_LOW, is it because my devices is running low on battery? But while the testing is taking place, the device is having 58% battery.

Also, the device is connected to Jio 4g network.

The dumpsys log is included below, could anyone have some comments to give a light on the issue. :)


(scheduled) com.mypackage.testapp/com.firebase.jobdispatcher.GooglePlayReceiver{u=0 tag="test-sync-job" trigger=window{start=300s,end=360s,earliest=-459s,latest=-399s} requirements=[NET_ANY] attributes=[RECURRING] scheduled=-759s last_run=N/A jid=N/A status=READY_BATTERY_LOW retries=0 client_lib=FIREBASE_JOB_DISPATCHER-1}

Not yet run.


Thanks in advance :)

Midhu
  • 1,647
  • 2
  • 18
  • 29

1 Answers1

-1

Here is the bit of making a vocation.

Driver = new GooglePlayDriver(context); 

firebaseJobDispatcher = new FirebaseJobDispatcher(driver); 

Occupation constraintReminderJob = firebaseJobDispatcher.newJobBuilder() 

.setService(ReminderService.class) 

.setTag(REMINDER_JOB_TAG) 

.setConstraints(Constraint.DEVICE_CHARGING) 

.setLifetime(Lifetime.FOREVER) 

.setRecurring(true) 

.setTrigger(Trigger.executionWindow( 

REMINDER_INTERVAL_SECONDS, 

REMINDER_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS 

)) 

.setReplaceCurrent(true) 

.assemble(); 

firebaseJobDispatcher.schedule(constraintReminderJob); 

How about we investigate the above scrap.

Occupation

There are a few ascribes to make an occupation.

A string label that (inside your application) particularly recognizes the Job.

A JobService subclass that will contain all the business rationale identified with the Job.

A JobTrigger will establish that the made Job is presently prepared to execute.

An arrangement of Constraints is required keeping in mind the end goal to execute the made activity. As a matter of course, it is unfilled which implies that Job will be kept running when the JobTrigger is initiated.

A RetryStrategy is in charge of taking care of the disappointment conditions. The default is taken care of utilizing exponential backoff procedure.

A lifetime that indicates the season of the activity in which it ought to stay planned. The

default is to keep the Job planned until the following boot.

Package is for client provided additional items. This is a discretionary parameter.

A boolean demonstrates whether the Job should rehash or not. The default is false which implies that the planned Job will execute just once.

A boolean shows whether the booked Job ought to supplant any prior Job

with a similar tag or not. The default an incentive for this boolean banner is false.

Once your activity is prepared, you can utilize plan() strategy to plan the activity.

open static void scheduleJob(Context setting) { 

FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context)); 

Occupation work = createJob(dispatcher); 

dispatcher.schedule(job); 

} 

ReminderService.class 

open class ReminderService broadens JobService { 

/** 

* This asynctask will run a vocation once conditions are met with the imperatives 

* As soon as client gadget gets associated with the power supply. it will produce 

* a warning demonstrating that condition is met. 

*/ 

private AsyncTask mBackgroundTask; 

@Override 

open boolean onStartJob(final jobParameters) { 

mBackgroundTask = new AsyncTask() { 

@Override 

ensured Object doInBackground(Object[] objects) { 

Setting = ReminderService.this; 

ReminderTasks.executeTasks(context, ReminderTasks.ACTION_CHARGING_REMINDER); 

Log.i("TAG", "onStartJob"); 

return invalid; 

} 

@Override 

secured void onPostExecute(Object o) { 

/* false means, that activity is finished. we would prefer not to reschedule it*/ 

jobFinished(jobParameters, false); 

Log.i("TAG", "onStartJob-OnPost"); 

} 

}; 

mBackgroundTask.execute(); 

return genuine; 

} 

@Override 

open boolean onStopJob(JobParameters jobParameters) { 

on the off chance that (mBackgroundTask != invalid) { 

mBackgroundTask.cancel(true); 

} 

Log.i("TAG", "onStopJob"); 

/* genuine means, we're not done, if you don't mind reschedule */ 

return genuine; 

} 

} 

There are three strategies that will be utilized while utilizing FireBase Job Dispatcher.

onStartJob(JobParameters params)- This is the underlying strategy that will be conjured when a vocation is called. It keeps running on the fundamental string. It will restore a Boolean which tells whether an occupation is remaining or not. Returning genuine demonstrates that more work is remaining. We can call jobFinished() when the activity is finished.

onStopJob(JobParameters params)- This technique is considered when your activity is halted. The activity can be halted because of different reasons if the running limitations related to the activity are never again fulfilled. It will restore a Boolean which tells whether work ought to be attempted again or not. On the off chance that returned genuinely, at that point, the system will set up this activity again for execution.

jobFinished(JobParameters params, boolean needsReschedule)- When work has been offloaded to another string, it ought to be called expressly.

Jignasha Royala
  • 1,032
  • 10
  • 27