是否可以使用 workmanger 而不是 ScheduledExecutorService 在每 n 分钟内显示插页式广告?
Is it possible to use workmanger instead of ScheduledExecutorService for showing interstitial ad in evey n minutes?
我想每 10 分钟展示一次插页式广告,大多数教程建议使用 ScheduledExecutorService,但我想知道是否可以改用 workmanager?
没有。 WorkManager 专门用于可延迟的、持久的工作,而不是用于 1) 绑定到您的 UI 或 2) 特定时间安排的工作。来自 WorkManager Overview:
The WorkManager API makes it easy to schedule deferrable, asynchronous tasks that are expected to run even if the app exits or device restarts.
WorkManager is not intended for in-process background work that can safely be terminated if the app process goes away or for tasks that require immediate execution. Please review the background processing guide to see which solution meets your needs.
我想每 10 分钟展示一次插页式广告,大多数教程建议使用 ScheduledExecutorService,但我想知道是否可以改用 workmanager?
没有。 WorkManager 专门用于可延迟的、持久的工作,而不是用于 1) 绑定到您的 UI 或 2) 特定时间安排的工作。来自 WorkManager Overview:
The WorkManager API makes it easy to schedule deferrable, asynchronous tasks that are expected to run even if the app exits or device restarts.
WorkManager is not intended for in-process background work that can safely be terminated if the app process goes away or for tasks that require immediate execution. Please review the background processing guide to see which solution meets your needs.