简体   繁体   English

如何每5分钟启动一次调度程序,在Android 8(奥利奥)中没有任何失败 - (尝试过Jobcheduler最小限制为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)

How to run a service(to perform some task) exactly every 5 minute without any fail. 如何在没有任何失败的情况下每5分钟运行一次服务(执行某项任务)。 I had a working code for the above requirement using Alarmmanager but its failing since i am trying to target Android 8(Oreo). 我有一个使用Alarmmanager的上述要求的工作代码,但它失败了,因为我试图瞄准Android 8(奥利奥)。

  • Is it possible to achieve my usecase targetting Oreo or not ? 是否有可能实现我的目标Oreo?

There are lots of things in Android when put together, they won't work as expected. Android中有很多东西放在一起时,它们将无法按预期工作。 The problem you are facing has been solved by new WorkManager API. 您遇到的问题已通过新的WorkManager API解决。 From official documentation: 从官方文件:

WorkManager chooses the appropriate way to run your task based on such factors as the device API level and the app state. WorkManager根据设备API级别和应用程序状态等因素选择适当的方式来运行任务。 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. 如果WorkManager在应用程序运行时执行您的任务之一,WorkManager可以在您应用程序进程的新线程中运行您的任务。 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会选择适当的方式来安排后台任务 - 根据设备API级别和包含的依赖项,WorkManager可能会使用JobScheduler,Firebase JobDispatcher或AlarmManager。

So WorkManager will take care of what to run based various factors and makes everything a lot easier and cleaner. 因此,WorkManager将根据各种因素来处理运行内容,并使一切变得更加容易和清洁。

For your scenario, You can use recurring tasks: 对于您的方案,您可以使用重复任务:

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

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

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