前回(
http://blog.tappli.com/article/44407843.html)記事にしたAsyncTaskのバグについてですが、調べても調べても具体的な内容はネタ元と思われる以下のサイトしか出てきません…。
http://groups.google.com/group/android-developers/browse_thread/thread/07ea01892ee7a5f4/9f71428217c2cd44あと、AsyncTaskの修正履歴を以下から確認してみたのですが、2010/09/10の修正ではThreadPoolExecuterのKeepAliveTimeを10から1に変更しただけで、その他の修正は行われていないっぽいのです。
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=history;f=core/java/android/os/AsyncTask.java;h=5fb1d7c32879352170abbd6c56c1aa81f5fae175;hb=refs/heads/gingerbreadこの修正で前回記事にした内容の不具合が直るとは思えないんだけれど…。
もしかしてネタ元が英語だったために、僕が読み間違えている可能性もあると思い、がんばって翻訳してみました。
英語は得意でないので、間違っているところとか、日本語としておかしいところは多々あるかと思いますが、それでも話の大筋としては、下記の翻訳で間違っちゃいないと思っています。
そうするとやっぱり不具合はあったということで、一体どういうことなのよ?という気分です。
onDestroy()でAsyncTaskのcancel()を実行しても、onPostExecute()が呼ばれるというのは本当に起こり得るのかしら?
Froyo以前にバグが残っているとしたら困るなぁ…。
--------------------------------
As far as I can tell, AsyncTask's cancel method doesn't work as advertised.
私が言える範囲では、AsyncTaskのcancel()メソッドは(公示通りに)きちんと動かない。
I can't tell whether this is a bug, or me not understanding AsyncTask's cancel() method.
私はこれがバグかどうかは言えない、AsyncTaskのcancel()メソッドについて理解していない。
I'm asking here instead of StackOverflow because I suspect it's a bug.
私はStackOverflowに代わってここで質問する。バグを疑っているから。
I understand from past discussions here that cancel() isn't meant to actually kill a thread
ここでの過去の議論から、cancel()が実際にスレッドを殺すわけではないことは分かっている。
(though the description of the mayInterruptIfRunning flag sure implies it is).
(mayInterruptIfRunningフラグの説明は、それを意味しているはずなのに)
But I'm also checking for isCancelled() (which is returning false),
私はisCancelled()も確認して(それはfalseを返す)、
and trying to use the onCancelled callback (which isn't getting called), to no avail.
onCancelled()コールバックを使おうとした(それは呼ばれなかった)が、無駄に終わった。
My situation is that I have a (short-running, one small network call) AsyncTask that begins in my Activity's onCreate.
状況しては、私は(1回小さな通信する短い処理の)AsyncTaskをActivityのonCreate()で開始する。
If the user backs out of the screen before it finishes though,
例えば、ユーザが画面を消して終了させるとき、
I need to either cancel the AsyncTask entirely,
完全にAsyncTaskをキャンセルするか、
or at least make sure its onPostExecute doesn't do any meaningful work.
少なくともonPostExecute()が意味のある(?)仕事をしないことを確認したい。
In my activity's onDestroy handler, I call cancel() on the task,
私のActivityのonDestroy()では、タスクのcancel()を呼んでいて、
and then inside the task I have an onCancelled handler that sets a boolean.
そして、そのときタスク内ではonCancelled()を受けてbooleanの値を設定している。
In my onPostExecute handler, I check isCancelled(),
onPostExecute()では、私はisCancelled()をチェックしていて、
and I also check to see whether the boolean has been set from onCancelled, and neither are.
そして、onCancelled()で設定されたはずの真偽値をもチェックしているのに、どちらもダメ。
I'm using the debugger, and the order of operations is:
私がデバッガを使っているときの操作手順は:
1) onDestroy(), calls task.cancel()
1) onDestroy()でAsyncTaskのcancel()を呼ぶ
2) task's onPostExecute runs, isCancelled() returns false,
2) タスクのonPostExecute()が実行され、isCancelled()はfalseを返すので、
so I have no conditional to stop the flow and that's it. onCancelled never runs.
私はタスクを停止させるための条件を得られない。onCancelled()は実行されない。
What am I doing wrong here?
私のやっていることは何か間違っていましたか?
I can't find any way to tell my task not to run its work in onPostExecute.
私はonPostExecute()でタスクが処理を行わないように命令する方法を見つけられない。
--------------------------------