SHARE
TWEET

Android Location Worker Thread

ScottHelme Dec 8th, 2012 1,105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***
  2.  * This task waits for the Location Services helper to acquire a location in a worker thread
  3.  * so that we don't lock the UI thread whilst waiting.
  4.  *
  5.  * @author Scott Helme
  6.  */
  7. class LocationWorker extends AsyncTask<Boolean, Integer, Boolean> {
  8.        
  9.         @Override
  10.         protected void onPreExecute() {}       
  11.        
  12.         @Override
  13.         protected void onPostExecute(Boolean result) {
  14.                 /* Here you can call myLocationHelper.getLat() and
  15.                 myLocationHelper.getLong() to get the location data.*/
  16.         }
  17.        
  18.         @Override
  19.         protected Boolean doInBackground(Boolean... params) {
  20.                
  21.                 //while the location helper has not got a lock
  22.                 while(myLocationHelper.gotLocation() == false){
  23.                         //do nothing, just wait
  24.                 }
  25.                 //once done return true
  26.                 return true;
  27.         }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top