android - Why application stops for some time and button also not pushed -


this gist of program.. when pressed button telling location works fine if geocoder not throw exception, problem comes when geocoder throws exception , @ same time application stop time hangs.. because progress bar stop rotating… , stop button not pressed… after 30 seconds or 1 min print no address found… can me separate out problem… thank in advance.

//this in oncreate method locationmanager = (locationmanager) getsystemservice(context.location_service); locationmanager.requestlocationupdates(locationmanager.gps_provider,1000,3, this);

//seperate mehtod public void geo(double latitude,double longitude) {

    if(geocoder.ispresent())     {          try          {          geocoder geocoder = new geocoder(getapplicationcontext(), locale.getdefault());      list<address> listaddresses = geocoder.getfromlocation(latitude, longitude, 1);          if(null!=listaddresses&&listaddresses.size()>0)         {              location = listaddresses.get(0).getaddressline(0);          }      else     {         toast.maketext(getbasecontext(), "searching..",dur).show();     }      }       catch (exception e)      {         //toast.maketext(this,location, dur).show();          toast.maketext(getbasecontext(), "no address found",dur).show();     }     }     else     {         toast.maketext(getapplicationcontext(),"wait...",dur).show();     } } 

this geo method called in onlocationchanged method after getting latitude , longitude, getting location.

i assume problem in geocoder's attempts location (maybe it's waiting response sensors or network). should execute request geocoder in separate thread prevent hanging (you can use asynctask it). noticed work ui, showing toasts, have done in main ui thread (you can use method runonuithread activity )


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -