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
}
}
基本上,我的目標是:我有一個活動。在此活動中,我執行的AsyncTask,但它不工作
- 緯度/經度不斷張貼到我的網站每分鐘左右。
- 當然,我想在另一個線程中這樣做,所以它不會弄亂我的UI線程。這個AsyncTask應該可以解決這個問題......但是它帶來了一個錯誤,我不知道爲什麼。
你能做些什麼來完成我的目標?這非常簡單...只需掃描位置並在後臺每分鐘發佈到網頁。
順便說一句,我的onCreate方法是這樣的。基本上就是這樣。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new ExecuteLocations().execute();
setContentView(R.layout.main_list);
}