我有一个处理程序,它每 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);
}
};
如您所见,我玩过 vars。有任何想法吗?谢谢
最佳答案
这有助于...将字符串与 equals 和以下 if 语句进行比较
if(!currentCity.equals("")){
if(!firstCity.equals(currentCity)){
firstCity = currentCity;
}
}
关于java - UpdateHandler,只有当触发器为真时才做一件事,Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3506616/