0

So my problem is as follows, I have an AsyncTask Class that is called from a preference file ie. The intent is called from within an xml file. This AsyncTask Class is continuously running as I am doing a real time FFT of the sound within a room and will only be cancelled if I hit the return button. I cant check for keys being pressed as this Class extends AsyncTask and therefore I cant end the thread properly so that it reaches its onCancelled() state. The only other way I can think about ending this is to make a standby class which is called from the xml file which in turn calls this class and calls the .cancel(true) on the class object.. Any other ideas around this?

4

1 回答 1

0

你能发布一些代码吗?

在您的调用方法(您可以在其中检查键)中,您可以调用myASyncTask.cancel(),然后在doInBackground()AsyncTask 的方法中,您可以检查isCancelled()然后中断循环并返回到onCancelled()AsyncTask 的覆盖方法。

http://developer.android.com/reference/android/os/AsyncTask.html#cancel(boolean)

这有帮助吗?

于 2013-09-22T20:26:35.290 回答