android


Back-off for a fixed period with JobScheduler


What I am trying to achieve is:
Three (may increase) JobServices are scheduled.
Each job keeps invoking on a difference set of RESTful APIs from a service until it decides to end.
The service API has an hourly quota limitation, and will return a certain code when invoked too frequently.
The quota is calculated for each application, meaning invocations by all three jobs are counted as a whole.
When a job receives the error code indicating the quota is exceeded, it stops running and wait for re-schedule.
Since the quota is hourly basis, the job only needs to wait for 60 minutes for the cool-down.
To test the back-off strategy, I had an experiment building the job like this:
new JobInfo.Builder(JOB_ID, new ComponentName(this, QuickJob.class))
.setOverrideDeadline(ONE_MINUTE)
.setMinimumLatency(HALF_MINUTE)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
Basicly what the QuickJob does is it logs the timestamp, calls jobFinished(params, true) and waits for Android to reschedule.
From the logs I could see that the first time the job stopped for approximately 1 minute, second time 2 minutes, then it's 4 minutes, 8, ..., which fits the description of the BACKOFF_POLICY_LINEAR policy.
However, in my case, as described in the beginning, I only need the job to back-off for an hour, not 1, 2, 4, 8 hours.
I thought about triggering the jobs at the start of every hour with AlarmManager, but I think it's nice to have the network type settings over the jobs.
Another possible solution I thought about is to have the jobs call jobFinished() with needsReschedule being false, but schedule themselves to run again in the next hour. But this just feels hacky and not... right.
So what are my choices now?

Related Links

How to retrieve one to one chat history from Openfire using asmack android
My android dontpanic folder is too big. can I delete stuff from it?
Defining recording area of MediaCodec encoder, MediaMuxer or virtualdisplay
Setting same Height and width of ImageView in percentage that is in Listview
How do I link to my Android app on device?
How to set marker in center of google map in android?
My app closes on start in the emulator. What's wrong?
Android HLS plays first segment then only audio
It is possible to pass a Class<> object in Android Layout XML?
Android SQLite Table out of range
How to connect Android Studio to Network and then to MS SQL?
Cordova FileTranfer plugin currupts image after uploading
Implementing Parcelable for a custom 2D array
Positioning of FAB button in Material design
Formatting a Simple Cursor Adapter
A fragment and 2 activity that use the fragment

Categories

HOME
phpword
assembly
turing-machines
delphi-7
gdb
ng-idle
wakanda
github-for-windows
3d
interface
themes
opendj
spring-session
nfs
performancepoint
line
flash-player
cumulocity
heat
keytool
git-extensions
topology
sar
ksh
cgbitmapcontext
systemtime
react-toolbox
parcelable
mongoid6
shared
jbutton
hibernate-search
slacktextviewcontroller
openerp-7
sim-toolkit
sql-server-ce
jpad
cd
sessionstorage
projects-and-solutions
chef-solo
trigonometry
postgresql-8.4
strftime
httrack
openal
builder
opengl-4
java-websocket
template-toolkit
py2neo
meteor-packages
stax
vulcanize
macaulay2
expectations
tooleap
lean
data-protection
dbamp
uiactionsheet
concept-insights
atan2
sciruby
uncompress
branch-and-bound
nsurlsessiondatatask
rapidsvn
nodelist
uncaught-typeerror
addressing-mode
structuremap3
paw
gii
build-script
xml-dsig
multiautocompletetextview
syndicationfeed
rfc5322
scriptaculous
scrypt
c++builder-xe5
inputmismatchexception
mvc-editor-templates
octal
sqlclr
wimax
veracity
faye
appjs
inkcanvas
floating-point-exceptions
urlrewriter
jqote
rmdir
quotation-marks
unattended-processing
undefined-index
load-time
dot-emacs
aspmenu
openfaces
django-piston
build-environment
entitykey

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App