Advertisement
Guest User

AsyncTask Example

a guest
Mar 10th, 2011
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1.     private class LocTask extends AsyncTask<Double, Void, List<Address>> {
  2.  
  3.         @Override
  4.         protected List<Address> doInBackground(Double... params) {
  5.             try {
  6.                 return geoCoder.getFromLocation(params[0], params[1], 1);
  7.             } catch (IOException e) {
  8.                 e.printStackTrace();
  9.                 return null;
  10.             }
  11.         }
  12.  
  13.         @Override
  14.         protected void onPostExecute(List<Address> result) {
  15.             locationChanged(result);
  16.         }
  17.     }
  18.  
  19.     @Override
  20.     public void onLocationChanged(Location loc) {
  21.         mylat = loc.getLatitude();
  22.         mylong = loc.getLongitude();
  23.  
  24.         new LocTask().execute(mylat, mylong);
  25.     }
  26.  
  27.     public void locationChanged(List<Address> addresses) {
  28.         // do stuff (if addresses != null)
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement