Reputation: 6136
I've created an asynctask in my MapActivity, here it is:
class ReadLocations extends AsyncTask<String, String, String> {
GeoPoint apoint1;
GeoPoint apoint2;
ArrayList<GeoPoint> Locations = new ArrayList<GeoPoint>();
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MyMapLocationActivity.this);
pDialog.setMessage("DONE");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
return null;
}
protected void onPostExecute() {
// dismiss the dialog once done
pDialog.dismiss();
}
}
I'm trying to execute it this way:
public class MyMapLocationActivity extends MapActivity {
private MapView mapView;
private ProgressDialog pDialog;
private ProgressDialog eDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ReadLocations Read = new ReadLocations();
Read.execute();
...
My controlling dialog never disappears - it seems like my onPostExecute method is not called - why is that?
Upvotes: 0
Views: 688
Reputation: 4753
You have not correctly overridden onPostExecute, the result parameter is missing
It should be something like
@Override
protected void onPostExecute(String result) {
// dismiss the dialog once done
pDialog.dismiss();
}
Upvotes: 1
Reputation: 12350
in Eclipse the best and the easiest way to override or implement methods of super classes correctly is:
AsyncTask
body. Then mouse right click
--> source
--> override/implement methods
. Also you can generate constructors, getters/setters etc this way .
Upvotes: 0
Reputation: 109237
Becoz, your AsyncTask's onPostExecute()
have not argument. which is return by doInBackground()
.
SO override correctly both methods.
Something like,
@Override
protected String doInBackground(String... args) { // Return type of same as argument of onPostExecute()
return null;
}
@Override
protected void onPostExecute(String result) { // Add String argument in onPostExecute()
// dismiss the dialog once done
pDialog.dismiss();
}
As possible of execution of doInBackground()
is fast because there is no any other work implementation in it. only one return statement..
Upvotes: 1