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

FirebaseRecyclerViewAdapter display child's from multiple refs
Huawei Android Logcat not showing logs
Is shouldOverrideUrlLoading called for links within the same domain?
Getting User location lat lng with API 22
how to bring ProgressBar in center of the screen and remove warning message in react native
Android studio : Plugin with id 'com.android.application' not found
android - OutOfMemoryError while downloading data using Volley library
Error on adding googlemaps to my android app after updating Android Studio [duplicate]
Restrict app installation for particular version of android
Error Integrating Inmobi in Android App
Android - DrawerLayout set background for another side
After Double starting of Infinite soundPool, stop() function not work.Why?
Elevation animation on click on CardView
Accessing Google Apis from Android Emulator using Apache Cordova
Alarm Manager not firing on screen is off
Listview not working inside ScrollView

Categories

HOME
algorithm
asp.net-web-api
assembly
twitter-bootstrap-3
linkedin
twig
serialization
google-cloud-functions
tivoli
gembox-spreadsheet
qpython
syntaxnet
mel
resultset
naivebayes
tput
stellar.js
favicon
cumulocity
undertow
draft-js-plugins
fat
pylons
licensing
nsurl
mobx
left-join
kodi
fossil
nested-lists
python-import
imx6
salesforce-communities
doc
android-ibeacon
movilizer
microsoft-metro
bindingnavigator
contract
android-exoplayer
phpdbg
xbmc
arq
wpas
jqchart
arules
bbpress
offline.js
cmp
google-photos
vibrate
builtins
centrifuge
envi
neon
gogs
clipboard.js
http-status-code-401
kango-framework
cortex-m
relativelayout
dynatree
gocql
ansi
omnifaces
umlgraph
mass-assignment
apache-spark-1.3
nodelist
entry-point
human-computer-interface
gii
grails-plugin-rabbitmq
clickbank
ice-cube
oocss
inappsettingskit
nebula
flex++
diem
video-codecs
sqlclr
zope.interface
subgraph
expression-blend-4
svk
metaweblog
cruisecontrol.rb
updatesourcetrigger
opml
pos-for-.net
soappy
mathematical-typesetting

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile