简体   繁体   English

每天在特定时间运行代码

[英]Run code at specific time, every day

I want to disable service at [user choice] and enable it at [user choice] for every day. 我想在[用户选择]禁用服务,并在[用户选择]每天启用它。 What is the best way to accomplish that? 实现这一目标的最佳方法是什么?

Should i use Calendar? 我应该使用日历吗? (Calculate start and end times, or something else? ) (计算开始和结束时间,或其他什么?)

From Justin Breitfeller's answer to Android Java - Creating a Cronjob : 从Justin Breitfeller对Android Java的回答- 创建一个Cronjob

The Android AlarmManager is the class you are looking for. Android AlarmManager是您要查找的类。 It can trigger an intent to be sent to your application at set intervals so you can run any task you would like. 它可以按设定的时间间隔触发发送到您的应用程序的意图,以便您可以运行任何您想要的任务。

What you looking for is called 'Cron'. 你要找的是'Cron'。 It can be achieved with the AlarmManager . 它可以通过AlarmManager实现。 AlarmManager myAlarmManager = Context.getSystemService(Context.ALARM_SERVICE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM