Android的日程行动日程、行动、Android

2023-09-06 00:34:44 作者:痴心易碎 ∞

若要一段时间,我发现有几个选择一些行动:

使用AlarmManager 使用ScheduledExecutorService的 使用处理程序的方法postDelayed

这一切最大的区别是什么?是什么使计划操作的最佳实践?

解决方案 AlarmManager 是全球性的计时器,这个人能唤醒你的应用,即使它没有启动。重的家伙。 ScheduledExecutorService的:标准的Java方法做一些计划的东西,在JSE,简单和熟悉的Java开发人员使用。这项工作将在不同的线程比UI或线程调度此作业执行。非常适合于服务不处理用户界面和proccess长,重的东西。 处理程序:Android的方式来安排作业,作业在UI线程执行(如果处理程序是在用户界面创建的),因此它不能很重等待处理,或者会只是冻结您的UI。

To make some action for some time I found that there are several choices:

use AlarmManager use ScheduledExecutorService use Handler's method postDelayed any do日程管理怎么样 日程管理也能小清新

What is big difference of all this? What is the best practice of making schedule action?

解决方案

AlarmManager is the global "Timer", this man can wake your application up, even if it wasn't started. Heavy guy. ScheduledExecutorService: standard Java way to do some scheduled stuff, used in JSE, simple and familiar for Java developers. The job will be executed in different thread than UI or thread that schedule this job. Well suited for services not to deal with UI and to proccess long and heavy stuff. Handler: Android way to schedule job, job executes in UI thread (if the handler was created in UI), so it cannot be very heavy proccessing or it'll just freeze your UI.