Method doInBackground() works well, but never call onPostExecute(). Method onPostExecute() override right, I do not cancel the AsyncTask and start the task with execute() method. I can not understand that behaviour.
Start the task:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
httpClient = new HttpClient();
new GetRepositoriesAsyncTask().execute("android");
}
Async class:
private class GetRepositoriesAsyncTask extends AsyncTask<String, Integer, ArrayList<Repository>>{
@Override
protected ArrayList<Repository> doInBackground(String... queries) {
try {
return httpClient.getRepositories(queries[0]);
} catch (IOException | JSONException e) {
e.printStackTrace();
return null;
}
}
@Override
protected void onPostExecute(ArrayList<Repository> repositories) {
if (repositories != null) {
adapter.addItems(repositories);
} else {
Toast.makeText(MainActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
}
}
}
Thanks