问题描述
我有一个利基应用程序需要每隔几秒向服务器发送它的位置。 (不要担心手机的电池寿命)。我将如何每隔几秒就创建一个线程或执行某些操作?我有一个gpslistener,但它的子类的名称是放置在 onCreate 服务中。
mTimer.scheduleAtFixedRate(new TimerTask(){
@Override
public void run(){
//想要去这里
}
},0,REFRESH_TIME);
REFRESH_TIME 是以毫秒为单位的频率或时间当运行重复自身。
I have a niche application that needs to send a server its location every few seconds. (Don't worry about a mobile phone's battery life). How would I make a thread or something execute every few seconds? I have a gpslistener but the name of its subclass is "onlocationchanged" which seems to only want to provide information if the location changed, I will need an updated location sent to the server every time though on an interval that I define
How would I do this?
insight appreciated
Place this in onCreate of a service.
mTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { // What you want to do goes here } }, 0, REFRESH_TIME);
REFRESH_TIME is the frequency or time in milliseconds when the run repeats itself.
这篇关于Android使方法每X秒运行一次(涉及gps和服务器调用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!