[英]AsyncTask when is onPostExecute() not called?
我正在努力确保我考虑了所有可能性,以避免用户出错。
我有一个 AsyncTask,它实现了一个接口,并在 AsyncTask 的 onPostExecute 中向调用类返回响应,如下所示:
public class GetVideoInfoFromDataBase extends AsyncTask {
Context context;
private AsyncInterface asyncInterface;
// Paginated list of results for alarm database scan
static PaginatedScanList<AlarmDynamoMappingAdapter> results;
// The DynamoDB object mapper for accessing DynamoDB.
private final DynamoDBMapper mapper;
public GetVideoInfoFromDataBase(Context context, AsyncInterface asyncInterface){
mapper = AWSMobileClient.defaultMobileClient().getDynamoDBMapper();
this.context = context;
this.asyncInterface = asyncInterface;
}
@Override
protected Object doInBackground(Object[] params) {
System.out.println("The backgrond stuff is working 1");
DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
results = mapper.scan(AlarmDynamoMappingAdapter.class, scanExpression);
return results;
}
@Override
public void onPostExecute(Object obj) {
asyncInterface.response((PaginatedScanList<AlarmDynamoMappingAdapter> )obj);
}
}
是否有任何时候不会调用 onPostExecute 意味着接口不会返回值?
在此先感谢您的帮助。
只要doInBackground()
返回并且您没有显式取消任务(通过在您的AsyncTask
实例上调用cancel()
, onPostExecute()
就会运行。
从技术上讲, onPostExecute()
将在(并且如果)以下行成功执行后被调用:
return results;
只要您的进程没有在此期间被杀死。
如果您已取消任务, onCancelled()
将代替援引onPostExecute()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.