Nicholas Muir Nicholas Muir - 8 months ago 42
Android Question

AsyncTask when is onPostExecute not run?

I am trying to ensure that I account for all possibilities to avoid errors for the user.

I have a AsyncTask that implements an interface and returns a response to the calling class in onPostExecute of the AsyncTask as below:

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;


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;

public void onPostExecute(Object obj) {

asyncInterface.response((PaginatedScanList<AlarmDynamoMappingAdapter> )obj);

Is there any time that onPostExecute would not be called meaning the interface would not return a value?

Thanks in advance for your help.


It runs as long as doInBackground() returns (with something, even a null).

Technically, onPostExecute() will get called after (and if) the following line gets executed successfully:

return results;

As long as your process does not get killed in the meantime.