Advertisement
ScottHelme

Android Location Worker Thread

Dec 8th, 2012
1,700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement