Hello everyone,
I had this issue using Geocoder's function getFromLocation(). According to
the docs it should be called inside a separate thread from the primary UI
thread. I did it and called it inside the doInBackground() of the AsyncTask
class. Now the issue is even I implemented it that way still the front end UI
is still affected if the internet connection is slow or totally cutoff. I have
tried using Handlers and also using new Thread( new Runnable() ... )
implementation still blocks the UI Thread. Below is the snippet of my AsyncTask
implementation.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
ReverseGeocodeLookupTask task = new ReverseGeocodeLookupTask();
task.execute(DESTLAT,DESTLONG);
}
public class ReverseGeocodeLookupTask extends AsyncTask <Double, Void, String>
{
@Override
protected void onPreExecute()
{
}
@Override
protected String doInBackground(Double... location)
{
Log.v( TAG , "inbackground");
Geocoder coder = new Geocoder(MyClass.this);
try {
//just return Success or Error to demonstrate that calling this
function still blocks the UI thread
coder.getFromLocation(DESTLAT, DESTLONG, 2);
return "Success";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "Error";
}
}
@Override
protected void onPostExecute(String result)
{
Log.v(TAG ,"Result: " + result);
}
}
Hoping for your help. Thanks.
- Brian
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en