According to the Android API document, onCancelled() exists from API level 3, and onCancelled(Object result) was added only from API level 11. In this regard, if the platform API level is below 11, onCancelled() will always be called, and onCancelled(Object) will always be called differently.
So, if you want to run your code at all levels of API 3 and above, you need to implement both methods. To have the same behavior, you might want to store the result in an instance variable so that isCancelled() can be used as shown below:
public class MyTask extends AsyncTask<String, String, Boolean> { private Boolean result;
By the way, Eric code is unlikely to work, because the Android API document says:
Calling the cancel() method will result in a call to onCancelled(Object) in the user interface thread after doInBackground(Object[]) returned. Calling the cancel () method ensures that onPostExecute(Object) never called.
IdleSun Dec 13 2018-12-12T00: 00Z
source share