AsyncTask was not designed for long running operations and should
definitely not be used in the way you describe here. To cancel a task,
just invoke cancel().

On Fri, Apr 9, 2010 at 10:50 AM, HippoMan <hippo.mail...@gmail.com> wrote:
> I know how to use AsyncTask in a standard manner to manage operations
> that are in the background in relation to a UI thread.
>
> However, I want to run a task in the background which might run for a
> very long time under certain circumstances. In these cases, I would
> like to force the background task to fail if it runs for an excessive
> amount of time.
>
> I know that I can invoke the "get(long timeout, TimeUnit unit)" method
> of AsyncTask in my UI thread in order to terminate my background task
> if it runs too long. However, in that case, my UI will block while
> this "get()" command is waiting.
>
> There are probably other drawbacks to directly calling "get()" in this
> manner, not the least of which being an evil interaction with the
> "done()" method of AsyncTask's contained FutureTask object, which
> itself is calling "get()" -- at least this is what I see when I look
> at the source code for AsyncTask.
>
> So what is the canonical, Android-approved method for timing out an
> overly-long-running AsyncTask?
>
> Thanks in advance.
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
> To unsubscribe, reply using "remove me" as the subject.
>



-- 
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to