Hi and thanks for your attention,
I have the following code, which
- starts an AsyncTask when a button is pressed
and
- should stop the AsyncTask when the button is released.
But this does not happen...
(the AsyncTask continues until its natural end, when the MAXX value is reached)
Please what am I doing wrong?
class right extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... unused) {
while (x < MAXX) {
if (x < MAXX)
x++;
publishProgress();
SystemClock.sleep(40);
}
return (null);
}
@Override
protected void onProgressUpdate(Void... unused) {
horizontal.scrollTo(x, 0);
Log.e("x", Integer.toString(x));
}
@Override
protected void onPostExecute(Void unused) {
}
}
left.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
right righttask = new right();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
righttask.execute();
break;
case MotionEvent.ACTION_UP:
righttask.cancel(true);
Log.e("","SHOULD STOP ASYNCTASK!!!");
break;
}
return false;
}
});