我有一个处理程序,每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一样。有任何想法吗?感谢
答案 0 :(得分:1)
这有助于...将字符串与equals和以下if语句进行比较
if(!currentCity.equals("")){
if(!firstCity.equals(currentCity)){
firstCity = currentCity;
}
}