Android的 - 实现一些像Unix的cronjobAndroid、Unix、cronjob

由网友(丶你亲爹临终前)分享简介:我想执行一个REST API请求每隔X分钟更新我的应用程序使用的数据库。 I would like to perform a REST API request every X mins to update the database my application uses. 这应该发生的我的应用程序是否正在运行与否。...

我想执行一个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 /启动服务在启动/

阅读全文

相关推荐

最新文章