search

Home  >  Q&A  >  body text

java - How to achieve precise timing execution of tasks?

I want to use a service to implement a function that executes a piece of code (check out, submit to the server in GET mode, and do not open the activity if it can be opened) at a scheduled time (23:59) every day. I use TimerTask and Handler, but this is quite good. It's unreliable and basically doesn't work when the screen is turned off.

Later I heard about AlarmManger and JobScheduler. After reading the documentation, it seems that they are specially used to open Activity. What kind of logic should I use to complete the automatic checkout action?

怪我咯怪我咯2781 days ago648

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-27 17:42:06

    AlarmManger does not say that it is specifically used to open Activity. It can open Broadcast, Service, and Activity. It depends on how you instantiate the Intent when you build the timer. As far as I know, the time AlarmManger initiates the alarm will have errors and inaccuracies for different mobile phones, especially Xiaomi machines. This may be a problem with the hardware clock. Don't know much about the others. for reference only.

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-27 17:42:06

    Android control is becoming more and more strict, but you should still use it JobScheduler吧, JobSchedulerThe original intention of the design is to make reasonable use of mobile phone resources.

    reply
    0
  • Cancelreply