java - Threading and Progressbar in Android? -


hey guys i'm trying display gps distance between user , place on card can see. problem is, think main thread splits or 2 things @ once. @ code below, android makes toast while doing code in if(flag) statement... toasts gps difference without getting coordinates of user...how make that, if(flag) statement first goes on toast after , outside if statement?

@override public void onresume() {     super.onresume();     imagepath = getintent().getstringextra("imagepath");     if(imagepath == null)     {         toast.maketext(this,"hello everyone",toast.length_long).show();     }     if(newcardadded)     {         flag = displaygpsstatus();         if(flag)         {             editlocation.settext("please!! move device to" +                     " see changes in coordinates." + "\nwait..");             pb.setvisibility(view.visible);             locationlistener = new mylocationlistener();//locationlistener physically gets location             locationmanager.requestlocationupdates(locationmanager.gps_provider, 5000, 10, locationlistener);           }         else         {             alertbox("gps status!!", "your gps is: off");         }             global_class.getinstance().getvalue().getlatitude = place_lat;             global_class.getinstance().getvalue().getlongitutde = place_lon;             string gps_distance = string.valueof(gps_difference(user_lon, user_lat,place_lon,place_lat));             toast.maketext(this, gps_distance, toast.length_long).show();      }  } 

locationmanager#requestlocationupdates

your locationlistener must implement onlocationchanged(location) method, called each location update. calculate distance , make toast in method. because requestlocationupdates(...) runs in thread, there's no way confirm done before toast.maketext(...), must use mylocationlistener.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -