friends,
i am using following code inside asyncTask
public class AsycLoaderFromDbAndMapInjector extends AsyncTask
{
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Boolean doInBackground(Void... arg0) {
Log.d("Asynctask", ""+arg0);
boolean show = false;
if(db == null)
db = new dbHelper(me);
ATM results = null;
try {
results = db.getAtmsBySelectedBanks(atm.getSelectedBankList(), selectedCity);
if (results != null) {
LoopThroughEachATMToDisplayOnMap();
}
return show;
}
@Override
protected void onPostExecute(Boolean result) {
stopProgress();
}
private void LoopThroughEachATMToDisplayOnMap()
{
Drawable drawable = getResources().getDrawable(
R.drawable.marker);
itemizedOverlay = new MyItemizedOverlay(drawable, mapView);
for (int i = 0; i < atm.getAtmList().size(); i++) {
ATM a = atm.getAtmList().get(i);
if (a != null) {
int[] coordinates = getIntCoordinates(a
.getCoordinates());
if (coordinates != null) {
GeoPoint point = new GeoPoint(coordinates[0],
coordinates[1]);
OverlayItem overlayItem = new OverlayItem(
point, a.getBankName(), a.getAddress()
+ "@@" + a.getPhone() + "@@"
+ a.getWebAddress() + "@@"
+ a.getCoordinates());
itemizedOverlay.addOverlay(overlayItem);
System.out
.println("coordinates-------------------------"
+ i + " "
+ coordinates[0]
+ ","
+ coordinates[1]);
}
}
}
}
}
now when i press back button this runable populate keeps running in the backend i have used
AsyncTask.cancel() on backbuttonpressed event but still it keeps running any one guide me how to solve this issue?
Try this,
set a flag in LoopThroughEachATMToDisplayOnMap(), to stop the for loop when the back button is pressed.
That is,
Detect when the back button is pressed, set the condition variable.
Inside the loop through method there is a condition variable which will break the for loop.