Android的 - 实现一些像Unix的cronjob [英] Android - implement something like a Unix cronjob

查看:143
本文介绍了Android的 - 实现一些像Unix的cronjob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行一个REST API请求每隔X分钟更新我的应用程序使用的数据库。

I would like to perform a REST API request every X mins to update the database my application uses.

这应该发生的我的应用程序是否正在运行与否。这也意味着,如果用户重新启动他们的移动,轮询应通俗易懂启动,而不需要先运行该应用程序。

That should happen whether my application is running or not. That also means, if the user restarts their mobile, the polling should start straightaway, without the need to run the application first.

基本上我想要实现这个样的Unix的cronjob的

Basically I want to implement kind of this Unix cronjob

*/5 * * * * /usr/local/bin/update_something.sh

这是可能通过Android服务?如果是的话,可以请你给我一些基本的方向?

Is that possible via the Android Services? If so, can you please give me some basic directions?

感谢。

推荐答案

是的,你可以使用服务,但需要触发/在某个时间点有关启动的服务。您可以尝试使用类,如 AlarmManager ,可以触发您服务每x分钟。

Yes you can use a service but a service needs to be triggered/started at some relevant point of time. You can try using classes like AlarmManager that can trigger your service every x mins.

http://developer.android.com/reference/android/app/ AlarmManager.html

编辑 -

要在设备启动时开始为您服务,您可以使用广播接收器

To start your service at device boot you can use a broadcast receiver

<action android:name="android.intent.action.BOOT_COMPLETED" />

清洁香港这个环节出

Chk this link out

http://www.androidcompetencycenter.com/2009/06 /启动服务在启动/

这篇关于Android的 - 实现一些像Unix的cronjob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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