Я использую Asyntask для google placeclient api, метод doinbackground работает очень хорошо, но данные не передаются в onPostExecute. Код:
@Override
protected ArrayList<AutocompletePrediction> doInBackground(String... params) {
AutocompleteSessionToken token = AutocompleteSessionToken.newInstance();
FindAutocompletePredictionsRequest request = FindAutocompletePredictionsRequest.builder()
.setTypeFilter(TypeFilter.ADDRESS)
.setSessionToken(token)
.setQuery(etxtSearchPlace.getText().toString())
.build();
placesClient.findAutocompletePredictions(request)
.addOnSuccessListener((response) -> {
for (AutocompletePrediction prediction : response.getAutocompletePredictions()) {
// mResult.append(" ").append(prediction.getFullText(null) + "\n");
Log.i(TAG, prediction.getPlaceId());
Log.i(TAG, prediction.getPrimaryText(null).toString());
Toast.makeText(SearchPageActivity.this, prediction.getPrimaryText(null) + "-" + prediction.getSecondaryText(null), Toast.LENGTH_SHORT).show();
}
/* play along with the API response */
tempResult=response.getAutocompletePredictions();
}).addOnFailureListener((exception) -> {
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
Log.e(TAG, "Place not found: " + apiException.getStatusCode());
}
});
return null;
}
Код onPostExecute выполняет передачу пустых данных в метод populateSearchResults.
@Override
protected void onPostExecute(ArrayList<AutocompletePrediction> tempResult) {
super.onPostExecute(tempResult);
if (tempResult != null) {
populateSearchResults(tempResult);
} else {
swipeView.setRefreshing(false);
}
}
}