private class ExecuteLocations extends AsyncTask<String, Void, Void>{
private final ProgressDialog dialog = new ProgressDialog(ListProfiles.this);
protected void onPreExecute() {
//this.dialog.setMessage("Starting pre-execute...");
//this.dialog.show();
}
@Override
protected Void doInBackground(String... arg0) {
check_profiles_lm=(LocationManager) ListProfiles.this.getSystemService(LOCATION_SERVICE);
myLocListen = new LocationListener(){
@Override
public void onLocationChanged(Location location) {
HashMap params = new HashMap();
params.put("lat", Double.toString(location.getLatitude()));
params.put("long", Double.toString(location.getLongitude()));
postData("http://mydomain.com",params);
}
@Override
public void onStatusChanged(String provider, int status,Bundle extras) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
};
check_profiles_lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 30000, 0, myLocListen);
return null;
}
protected void onPostExecute(final Void unused) {
if (this.dialog.isShowing()) {
//this.dialog.dismiss();
}
//Do something else here
}
}
Basically, my objective is:
- Constantly post the latitude/longitude to my website every minute or so.
- Of course, I want to do this in another thread, so it doesn't mess up my UI thread. This AsyncTask is supposed to solve that...but it's bringing up an error and I don't know why.
What can you do to accomplish my objective? It's very simple...just scan location and post to web every minute, in the background.
By the way, my onCreate method is like this. That's basically it.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new ExecuteLocations().execute();
setContentView(R.layout.main_list);
}