如何循环或Android的重复任务定期? [英] How to loop or to repeat periodically task in Android?

查看:267
本文介绍了如何循环或Android的重复任务定期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新到Android,和我真的想知道的是如何循环或定期重复的任务。
在我的计划,我有我的发送GPS位置我DATABSE UpdateLoc(),但我想它定期更新(无论是3分钟或3小时),而无需使用太多的电池和CPU。
问题是,我不知道从哪里开始...有一个简单的方法来做到这一点?

I am quite new to Android, and I am really wondering about is how to loop or to repeat periodically a task. In my program, I have UpdateLoc() that sends my gps location to my databse, but I want it to update periodically (whether it be 3 min or 3 hours) without using too much battery and CPU. The problem is that I have no idea where to start... Is there a simple way to do this?

推荐答案

我相信你在这种情况下两种选择:

I believe you have two options in this case:


  1. 服务 - 这将留在后台运行,但使用更多的电池

  2. AlarmManager - 你可以计划在将来运行简单地执行更新操作的任务,应当使用较少的电池

这篇关于如何循环或Android的重复任务定期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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