重复的方法每60秒用Java在Android [英] Repeating a method every 60 seconds in Java on Android

查看:935
本文介绍了重复的方法每60秒用Java在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我忙着为我的手机应用程序的项目。我不是一个程序员,所以到目前为止,已经学会为Android位的Java。

I am busy with a application for my phone for a project. I am not a programmer, so have learnt a bit of java for android so far.

我坚持上运行的方法,每隔60秒,而应用程序在手机上运行。

I am stuck on running a method every 60 Seconds while the application is running on the phone.

该应用程序使用GPS,然后发送用户ID和放大器;全球定位系统共同ords到服务器

The application uses the GPS and then sends a User Id & Gps co-ords to a server.

所以我有获取位置和放一个方法(getLoc);然后调用发送到服务器的方法,并保存到SD卡的方法。

So I have a Method (getLoc) that gets the Location & then calls the send to server method and save to SD card method.

这是对概念和放大器的证明;我只需要当手机连接到车载充电和放我的车跑在未来几天申请;使其无法入睡。我需要记录一些测试数据(GPS COORDS),而我开车在周围未来几天。

This is for proof of concept & I only need to run the application over the next few days in my car while the phone is connected to the car charger & not allowing it to sleep. I need to log some "test" data (GPS Coords) while I drive around over the next few days.

我只是在寻找重复的方法,每隔60秒将数据发送到服务器的最简单方法,而位置经理运行和放大器;不断得到位置。

I am just looking for the easiest way to repeat the method every 60 seconds that sends the data to the server while the Location manager runs & gets the location constantly..

如何将保持方法getLoc运行每隔60秒?

How would I keep the method getLoc to run every 60 Seconds?

推荐答案

这种方法的几个问题:


  1. 您不能收集位置数据,所有的时间,因为当设备进入睡眠模式,用户进程停止执行以及网络暂停。

  1. You can not gather location data all the time, because when the device goes to sleep mode user processes stop executing and network is suspended.

运行GPS所有的时间将在几个小时之内耗尽电池。

Running GPS all the time will drain battery in a matter of hours.

如果您强制使用网络每隔60秒(通过AlarmManager,唤醒电话),那么网络将永远不会停止,这会杀了电池更快然后GPS。

If you force to use network every 60sec (via AlarmManager, waking the phone), then network will never shutdown and this will kill battery even faster then GPS.

是否要更新,即使用户不移动数据?因为,平均而言,用户不经常移动。

Do you want to update the data even if user does not move? Because, on average, users do not move often.

如果你想处理位置数据以正确的方式,那么它是不是仅仅在60秒的时间间隔收集位置更加复杂。我强烈建议你阅读这篇优秀的博客文章:的http:/ /android-developers.blogspot.com/2011/06/deep-dive-into-location.html

If you want to handle location data the right way, then it's more complex than simply gathering location at 60 sec interval. I highly suggest you read this excellent blog post: http://android-developers.blogspot.com/2011/06/deep-dive-into-location.html

和的第2部分:的http://blog.radioactiveyak.com/2011/06/deep-dive-into-location-part-2-being.html

这篇关于重复的方法每60秒用Java在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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