문제

I have an AsyncTask running. If the application is stopped (phone call, app switch etc.) my understanding is that onPostExecute() will never be called. So, as long as cancel(true) is used to cancel an AsyncTask, the running task will be notified of the cancellation. I don't mind having to check isCancelled() periodically in doInBackground(), but what concerns me is the publishProgress() calls that are littered throughout doInBackground. My understanding is that onProgressUpdate() runs on the main UI thread.

Does that mean that any calls to publishProgress() will crash the app if it has been stopped? Or is it just any UI updates within onProgressUpdate() that will cause a crash when the app has been stopped.

The reason I'm asking is because I'm wondering if I have to qualify each publishProgress() call with a check for isCancelled() or can I just check once in onProgressUpdate() before actually attempting to update any UI components.

도움이 되었습니까?

해결책

Android documentation states:

onProgressUpdate(Progress...) will not be called if the task has been canceled. developer.android.com/...AsyncTask#publishProgress

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top