SW/Android

AsyncTask

MG_ 2020. 8. 15. 12:30

* AsyncTask


> boolean cancel(boolean mayInterruptIfRunning)

- mayInterruptIfRunning 는 실행중인 작업을 취소할지의 여부를 결정

: false 의 경우, doInBackground() 가 수행 완료 된 후에, onCancelled() 가 호출

: true 의 경우, 바로 종료하기 위한 Exception 을 던지기 때문에, doInBackground()에서 InterruptedException 발생

- cancel() 을 호출하더라도 작업을 일찍 끝내기는 어렵다. 좀 더 빠르게 작업을 종료하기 위해서는 doInBackground() 에서 isCancelled() 를 통해

종료하면, onPostExecute() 대신 onCancelled() 가 호출된다