I can not understand whether I ever made? I have a class which takes a reference to the input and the output gives me an object Document(Jsoup library). I then in the main stream parsing the object and set on the form data. at the beginning of the work I show ProgressDialog and at the end of it I'm. But everything works is unclear. I run a process asinktask starts and the form freezes (about a second). Sidebar does not have time to close. Then form droops ProgressDialog appears for a split second and closed. The data are mounted on the form. Everything is very fast, but what form freezes and ProgressDialog started only after it droops worries me.
public class MyAsincTask extends AsyncTask<String, Void, Document> {
private Document document;
private ProgressDialog progressDialog;
public MyAsincTask(Context context) {
progressDialog = MyProgress.getProgressDialog(context);
}
@Override
protected void onPreExecute() {
progressDialog.show();
super.onPreExecute();
}
@Override
protected Document doInBackground(String... params) {
try {
document = Jsoup.connect(params[0]).get();
} catch (IOException e) {
e.printStackTrace();
}
return document;
}
@Override
protected void onPostExecute(Document document) {
progressDialog.cancel();
super.onPostExecute(document);
}
}
and
public void setData(){
MyAsincTask task = new MyAsincTask(getActivity());
task.execute(link);
try {
document = task.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
guests = new ArrayList<>();
Elements elementsUserId = document.select("guest_id");
Elements elementsNumbers = document.select("room");
Elements elementsNames = document.select("name");
...
for (int i = 0; i < elementsNumbers.size(); i++) {
GuestBean guest = new GuestBean();
guest.setUserId(elementsUserId.get(i).ownText());
guest.setRoom(elementsNumbers.get(i).ownText());
guest.setName(elementsNames.get(i).ownText());
...
guests.add(guest);
count++;
}
GuestsListAdapter adapter = new GuestsListAdapter(getActivity(), guests);
list.setAdapter(adapter);
}