如何每 5 分钟启动一次调度程序,在 Android 8(Oreo) 中没有任何失败 - (尝试过的 Jobscheduler 最小限制是 15 分钟并且不可靠)

How to start a scheduler every 5 minute, without any fail in Android 8(Oreo) - (tried Jobscheduler minimum limit is 15minutes and is not reliable)

如何 运行 服务(执行某些任务)准确无误地每 5 分钟一次。我有一个使用 Alarmmanager 满足上述要求的工作代码,但由于我试图以 Android 8(Oreo) 为目标,所以它失败了。

Android 中有很多东西放在一起时,它们将无法按预期工作。您面临的问题已由新的 WorkManager API 解决。来自官方文档:

WorkManager chooses the appropriate way to run your task based on such factors as the device API level and the app state. If WorkManager executes one of your tasks while the app is running, WorkManager can run your task in a new thread in your app's process. If your app is not running, WorkManager chooses an appropriate way to schedule a background task--depending on the device API level and included dependencies, WorkManager might use JobScheduler, Firebase JobDispatcher, or AlarmManager.

因此 WorkManager 将根据各种因素运行 处理好内容,并使一切变得更加简单和清晰。

对于您的场景,您可以使用循环任务:

https://developer.android.com/topic/libraries/architecture/workmanager#recurring