简体   繁体   中英

How to start service automatically at specific time every day in Android?

我已经在我的应用程序中实现了服务活动,即我想在未先打开应用程序时在应用程序的后台获取数据。但是现在我想在特定或特定的时间启动服务,例如今天我的服务从下午12点,之后每天凌晨12点开始服务,请问该如何做。有人可以帮助我。谢谢。

As the comments state, AlarmManager is the class you're looking for. However it's not a great idea to start a service at an EXACT time, because if your app is popular and you have a million users, they're all going to hit your backend at exactly midday every day... Read more about the right way to do it here: https://developer.android.com/training/scheduling/alarms.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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