how to stop ASyncTask thread in android

后端 未结 2 630
难免孤独
难免孤独 2020-12-03 11:01
can anybody have any idea how to stop ASyncTask thread in android?.

Actually i have a loop which creates threads and executes them. and when this l

2条回答
  •  盖世英雄少女心
    2020-12-03 11:02

    In my case I perform server requests with HttpPost, HttpGet and so on. The only way I found to end an AsyncTask was calling the abort() method as you can see in the following example

    if (isCancelled) {
         try {
             //cancel the task and immediately abort the HttpRequest
             uploadTask.cancel(true);
             post.abort();
         } catch (UnsupportedOperationException e) {
             e.printStackTrace();
         }
    } 
    

提交回复
热议问题