I am looking for some advise about the following, I have a HttpUtil class (util) in which I have my sendGetRequest- and sendPostRequest methods. I use them to perform a successfull login to a website from which I am going to fetch some data. Now, I call these methods in my MainActivity in a Asynctask:
protected Boolean doInBackground(Void... params) { try { //1. GET request util.sendGetRequest(loginURL, null); //2. Post request util.sendPostRequest(loginURL, null); //3. Final GET request util.sendGetRequest(resultURL, null); // Read stream String[] response = util.readMultipleLinesRespone(); for (String line : response) { System.out.println(line); } } catch (InterruptedException e) { return false; } catch (Exception e) { e.printStackTrace(); } }
I am looking for a solution so that one waits for another to finish (1st get then post, finally get), if it`s possible I want to keep this util.class intact and not put everything in the Asynctask (doInBackground). Is this possible or do I have the wrong approach?
Your opinions and advise please.
Thank you in advance.