2016-10-01 65 views
2

我正在努力确保我能够为用户解决所有可能的错误。AsyncTask何时onPostExecute()未被调用?

我有一个实现一个接口,并返回下面的的AsyncTask的onPostExecute调用类的响应的AsyncTask:

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就不叫意接口的任何时间不会返回一个值?

在此先感谢您的帮助。

+1

应该调用'onPostExecute'。为什么不''onpostExecute'中的System.out.println'确保它是否被调用。 –

+0

它调用的很好。 –

+0

我在问有没有一种情况会导致它不被调用。 –

回答

2

onPostExecute()将运行只要doInBackground()回报,你没有明确取消任务(由您AsyncTask实例调用cancel())。只要你的程序没有得到在此期间丧生

return results; 

技术上,onPostExecute()将得到后(如果)被称为以下行被成功执行。

如果您已取消任务,将调用onCancelled()而不是onPostExecute()

相关问题