Android Worker Execute The Job Multiple Times
Solution 1:
You can use this following method : enqueueUniquePeriodicWork()
, and implement like that :
WorkManager.getInstance().enqueueUniquePeriodicWork("YOUR_TAG", ExistingPeriodicWorkPolicy.KEEP, workRequest);
Please notice that the second parameter is the key. The enum can be KEEP
or REPLACE
Solution 2:
I think i am late to answer this question and you might have tweaked it too.. But i am trying to help anyways..
The only thing that I do not understand is that every time the job execute multiple times,
can someone explain
why and how can i avoid it?
Explanation :
Everyone will be shocked if i will say :
- Googles android has no control over crores of processes running in real-time basis
- It even lacks to understand even say xyz process is completed? or running? or finished?
- This is it. And the outcome is the your issue
Oh my god.. It will lead to
data-loss
if i am doing any database operations then..!!??
Yes it results in data loss many times..
Does android and developers have any work around then...?
Yes, Prefer using IntentService
.
What is so special in
IntentService
?
If a intentservice
is already running and even if thousands
of times it gets called... Then in that case too... all calls are kept in queue
by android and processed one by one
and one after another
and after one is finished
then only another waiting awakes
and starts to execute it
Hope it helps.
Post a Comment for "Android Worker Execute The Job Multiple Times"