异步重复任务计划 [英] Asynchronous Repeating Scheduled Task

查看:109
本文介绍了异步重复任务计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎样才能创建一个的AsyncTask 这使一个固定的时间间隔后运行本身。

How does one create an AsyncTask which keeps running itself after a fixed interval of time.

有关如。从服务器获取数据每5分钟,给的通知的呼叫者线程,它已经收到的数据。我搜索的论坛,但找不到了。什么到目前为止,我已经收集的是,

For eg. get data from server every 5 minutes and give notification to caller thread that it has received the data. I searched on the forum but could not find much. What I have gathered so far is that

1),UI线程将调用的AsyncTask

1) A UI thread will call AsyncTask

2)上prexecute 执行之前UI线程访问

2) onPrExecute for UI thread access before executing

3) OnPostExecute 执行后,UI线程访问

3) OnPostExecute for UI thread access after executing

我不需要显示任何进展更新给用户。另外,当应用程序关闭该任务将被破坏。任何教程,这将有所帮助他。

I dont need to show any progress update to the user. Also, the task will be destroyed when the app closes. Any tutorial for this will he helpful

推荐答案

至于其他的意见建议。因此,让我更精细了。

As other suggested in the comments. So let me elaborate it more.

不要使用AsyncTask的。 INSTEAD去IntentService ONLY。

DON'T USE AsyncTask. INSTEAD GO FOR IntentService ONLY.


  1. 请一类扩展IntentService

  2. 使用报警管理器来触发一个意向,具体的行动项目自己的服务

  3. 定义一个接口用于通知该服务的客户端。

  4. 维护通过其客户端提供的这些接口实行对象的列表。

  5. 在onHandleIntent(意向意图)确定通过检查行动的呼吁。

  6. 启动数据直接intentService读取请求的使用工作线程工作,在你维护的接口对象列表的末尾呼吁更新委托。

  1. Make a class extends IntentService
  2. Use Alarm Manager to trigger a intent to your own service with specific action item
  3. Define a Interface to be used to notify client of this service.
  4. Maintain a list of these interface implemenation object provided by its client.
  5. in onHandleIntent(Intent intent) identify the call by checking action.
  6. Initiate the data fetch request directly on intentService as the use worker thread to work and in the end call update delegate of the interface object list you maintained.

请方法来让活动寄存器,从听这些更新注销。

Make methods to Let Activity register and unregister from listening these updates.

这篇关于异步重复任务计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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