Reputation: 31
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.
Upvotes: 1
Views: 362
Reputation: 1060
asyncTask in your activity:
private YourAsyncTask aTask;
instanitiate
aTask = new YourAsyncTask().execute();
cancel it like this:
aTask.cancel(true);
Upvotes: 0
Reputation: 4127
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.
Upvotes: 2
Reputation: 2009
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!!!
Upvotes: 1