views:

29

answers:

1

Hi,

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

+1  A: 

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

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