使用警报管理器与ScheduledExecutorService计划同一任务有什么区别

编程入门 行业动态 更新时间:2024-10-28 05:18:25
本文介绍了使用警报管理器与ScheduledExecutorService计划同一任务有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Internet上阅读,我们可以使用警报管理器和 ScheduledExecutorService 安排要在一定间隔内运行的任何事情。

Hi I was reading on internet that we can schedule any thing which we want to run at a gap of certain interval using alarm manager and ScheduledExecutorService.

我想知道它们之间的区别以及什么时候使用什么

I want to know what is the difference between them and what to use when

预先感谢。

推荐答案

ScheduledExecutorService 是内部的过程。如果您的流程由于其他原因而已经存在,例如正在提供前台UI,并且您希望使用 ScheduledExecutorService 进行定期工作,那就很好。但是,一旦您的应用移至后台,它的进程就可能随时消失,将您的 ScheduledExecutorService 与它一起使用,您将不再定期获得控制权。

ScheduledExecutorService is something inside your process. If your process is already around for other reasons, such as it is supplying the foreground UI, and you want to use ScheduledExecutorService for periodic work, that's fine. However, once your app moves to the background, its process may go away at any time, taking your ScheduledExecutorService with it, and you will no longer get control periodically.

AlarmManager 是您的过程外部。如果您正在寻找与Windows的预定任务或OS X / Linux cron 作业相对应的Android,则 AlarmManager (或在Android 5.0及更高版本上为 JobScheduler )适用。在某些情况下,您需要应用程序代码在后台定期运行,但很乐意允许您的进程在这两个周期之间终止。

AlarmManager is something outside your process. If you are looking for the Android equivalent of Windows' "Scheduled Tasks", or OS X/Linux cron jobs, that is what AlarmManager (or JobScheduler on Android 5.0+) is for. These are for cases where you need application code to run periodically in the background but are happy to allow your process to possibly be terminated in between those periods.

更多推荐

使用警报管理器与ScheduledExecutorService计划同一任务有什么区别

本文发布于:2023-11-13 12:25:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584356.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理器   警报   有什么区别   计划   ScheduledExecutorService

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!