我有一个处理程序,每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);
    }
};


就像您看到我玩过变种一样。有任何想法吗?谢谢

最佳答案

这有助于...将字符串与等号和以下if语句进行比较

if(!currentCity.equals("")){
    if(!firstCity.equals(currentCity)){
      firstCity = currentCity;
    }
}

关于java - UpdateHandler,仅当触发器为true时才执行操作,Android,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3506616/

10-10 19:49