Thank you for your response. If I use a fragment as a worker thread, I will
adapt the pattern in FragmentRetainInstance.java. Because it is unnecessary
for a worker fragment to start a asynctask, the worker thread can do the
task directly by using java.lang.Thread.

However, I still do not understand whether it is okay to add multiple
invisible fragments as worker threads to the UI and why it tries to stop
the thread in both onDestroy() and onDetach().

2013/2/1 Streets Of Boston <[email protected]>

> After your Fragment, the one without a UI, has started the AsyncTask, i.e.
> after the AsyncTask's 'execute' method has been called, it can stop it by
> calling 'cancel' on it.
>
>
> ....
> ....
> task.execute(...);
> ...
> ...
>
>
> And on some event, (Fragment's onDestroy for example), you just call.
> task.cancel(true);
>
> This will remove the task if it was scheduled or, if it is already
> running, interrupt the thread on which it is running.
> See more info about cancelling 
> here<https://developer.android.com/reference/android/os/AsyncTask.html#cancel(boolean)>
> .
>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to