How to completely kill/remove/delete/stop an AsyncTask

前端 未结 7 2102
终归单人心
终归单人心 2020-11-28 09:57

I made an app that downloads videos from our server. The issue is:

When i cancel the downloading i call:

myAsyncTask.cancel(true)

I

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 10:22

    AsyncTask does not cancel process on

    myAsynTask.cancel(true) 
    

    For that you have to stop it manually.

    for example you are downloading video in doInBackground(..) in while/for loop.

    protected Long doInBackground(URL... urls) {
    
             for (int i = 0; i < count; i++) {
              // you need to break your loop on particular condition here
    
                 if(isCancelled())
                      break;             
             }
             return totalSize;
         }
    

提交回复
热议问题