I am having issue that if AsyncTask
is running during fragment transaction then the fragments
become white(no content is displayed) so is there any way to stop AsyncTask
during fragment
transaction and resume once transaction is completed.
Asked
Active
Viewed 354 times
1

Ajeet Choudhary
- 1,969
- 1
- 17
- 41

Mubeen Iqbal
- 37
- 7
3 Answers
2
You have to call asyncTask.cancel()
and then your code in asyncTask.doInBackground()
must test periodically what isCancelled()
returns, if true it must return as soon as possible.
Finally when doInBackground returns asyncTask.onCancelled()
will be called on the UI thread.

from56
- 3,976
- 2
- 13
- 23
1
You have to keep the reference of the AysncTask
like:
MyAysncTask asyncTask = new MyAysncTask();
asyncTask.execute();
then in onPause()
or before calling transaction.commit()
call asyncTask.cancel()
.
Hope it will help!!!

Ajeet Choudhary
- 1,969
- 1
- 17
- 41
0
asyncTask in your activity:
private YourAsyncTask aTask;
instanitiate
aTask = new YourAsyncTask().execute();
cancel it like this:
aTask.cancel(true);

seon
- 1,050
- 2
- 13
- 27