Android AsyncTask blocks back key dispatch Event

前端 未结 2 1710
广开言路
广开言路 2021-01-17 03:39

The Problem is:

My Activity starts an AsyncTask in onStart(). In the doInBackground Method I make a short webrequest, and depending on your network connetion, this m

2条回答
  •  失恋的感觉
    2021-01-17 04:24

    This is the expected behavior. The documentation says :

    Cancelling a task

    A task can be cancelled at any time by invoking cancel(boolean). Invoking this method will cause subsequent calls to isCancelled() to return true. After invoking this method, onCancelled(Object), instead of onPostExecute(Object) will be invoked after doInBackground(Object[]) returns. To ensure that a task is cancelled as quickly as possible, you should always check the return value of isCancelled() periodically from doInBackground(Object[]), if possible (inside a loop for instance.)

提交回复
热议问题