UpdateHandler,仅当触发器为真时才执行操作,Android
我有一个处理程序,它每 5 秒在每次位置更新时接收一条消息。从该位置,我可以请求用户当前所在的城市。然后,我想仅在城市发生变化时下载一些数据。我怎样才能意识到这一点?
Handler myViewUpdateHandler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case UPDATE_LOCATION:
mc.animateTo(geosenseo.getCurrentPoint());
mapView.invalidate();
//a async task sets the currentCity field
if(trigger && (currentCity != "")){
firstCity = currentCity;
trigger = false;
}
if((currentCity != "") && (firstCity != "")){
if(firstCity != currentCity){
//download only when city changes
trigger = true;
}
}
}
super.handleMessage(msg);
}
};
正如你所看到的,我已经玩过变量了。有什么想法吗?谢谢
I have a handler that receives a message on every location update, every 5 secs. From the location I can request the current city the user is moving in. Then I want to download some data once and only when city changes. How can I realize that?
Handler myViewUpdateHandler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case UPDATE_LOCATION:
mc.animateTo(geosenseo.getCurrentPoint());
mapView.invalidate();
//a async task sets the currentCity field
if(trigger && (currentCity != "")){
firstCity = currentCity;
trigger = false;
}
if((currentCity != "") && (firstCity != "")){
if(firstCity != currentCity){
//download only when city changes
trigger = true;
}
}
}
super.handleMessage(msg);
}
};
like you can see I have played around with the vars. any ideas? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有助于...将字符串与 equals 和以下 if 语句进行比较
This helped...compare strings with equals and the following if statement