Reputation: 2874
As I know Android allows to start periodically services once per 15 minutes and maximum time of doing work in background is 10 minutes in Doze mode, but I think the code bellow avoid this limitation. Am I right?
public class TestWorker extends Worker {
@NonNull
@Override
public WorkerResult doWork() {
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
doPeriodicalyWork();
}
}, 0, 5000);
return WorkerResult.SUCCESS;
}
}
Upvotes: 2
Views: 236
Reputation: 4573
As I know Android allows to start periodically services once per 15 minutes
Yes, correct.
and maximum time of doing work in background is 10 minutes in Doze mode
Although I don't think I've seen it documented, I think this is about right, yes.
I think the code bellow avoid this limitation. Am I right?
Honestly, I don't see the reason why it would avoid the limitation. If the device is already in the Doze mode, doPeriodicallyWork()
simply will not be executed because the CPU will be sleeping. Wake locks are not allowed. It will only run during maintenance windows when the job scheduler, which holds the timer, is up.
The best way to figure this out is, of course, to try it out and test it. But I will be very surprised if you make it work. If so, it's worth filing a bug for Google :)
So, I think instead of trying to hack Android, you should focus on the root of the problem instead. Why do you need to do this in the first place? These limitations are not there for bothering Android developers, they are to save users from the developers which don't respect user's phone resources.
Upvotes: 1