Asynctask Execution Need To Cancel In Same Fragment When Make Request From Navigation Drawer's Every List Items
My Question is i need to open SAME FRAGMENT from Navigation Drawer's every List Item 's, and when fragment display, If AsynTask execution is On Going then AsyncTask execution shoul
Solution 1:
i found solution of my problem.
We just need to make request in onStop method like below :
@OverridepublicvoidonStop() {
super.onStop();
if(asyncTaskObject!=null){
asyncTaskObject.cancel(true);
}
}
This way whenever we request from Navigation Drawer's List Item on Same Fragment, at that time fragment call onStop() method and i just call task.cancel(true);
And Thanks to @MysticMagic. i resolved this issue from your given link.
Solution 2:
For forceful cancel()
to work, you will need to check if its cancelled in doInBackground.
@OverrideprotectedStringdoInBackground(String... params)
{
.
.
if(isCancelled()){
break;
}
.
}
Refer this: Why Android AsyncTask doesn’t stop after being cancelled
Hope it helps.
Post a Comment for "Asynctask Execution Need To Cancel In Same Fragment When Make Request From Navigation Drawer's Every List Items"