UpdateHandler,仅当触发器为真时才执行操作,Android

发布于 2024-09-15 11:57:05 字数 946 浏览 11 评论 0原文

我有一个处理程序,它每 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

π浅易 2024-09-22 11:57:05

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

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

This helped...compare strings with equals and the following if statement

if(!currentCity.equals("")){
    if(!firstCity.equals(currentCity)){
      firstCity = currentCity;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文