Android的日程行动 [英] Android schedule action

查看:200
本文介绍了Android的日程行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  1. 使用AlarmManager
  2. 使用ScheduledExecutorService的
  3. 使用处理程序的方法postDelayed

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

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

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

  1. use AlarmManager
  2. use ScheduledExecutorService
  3. use Handler's method postDelayed

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

解决方案

  1. AlarmManager is the global "Timer", this man can wake your application up, even if it wasn't started. Heavy guy.
  2. 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.
  3. 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.

这篇关于Android的日程行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆