0

Here is small example for to understand my question:

public class InitSettings_Task extends AsyncTask<Void, Void, Integer>  {
  @Override
  protected Integer doInBackground(Void... params) {
    request1result = request1;
    if (request1result) {
      result = httprequest2;
    } else {
      result = httprequest3;
    }  

    return result;
  }

  @Override
  protected void onPostExecute(Integer result) {
    //do something with result
  }
}

I know that Volley is a super library, but here i can't use it because my AsyncTask can ends before i will receive answer of first request.

Can somebody help me to understand what the best style for to send http request for this logic?

Before i have used Volley with Sleep() for to wait answer, but from my view it's not best sollution

Yevhen
  • 791
  • 9
  • 24
  • 1
    you should use some non async http client fx.: URLConnection or some http library which allows non async request like okhttp – Selvin Mar 16 '17 at 14:54
  • Thanks, for right direction) – Yevhen Mar 16 '17 at 15:08
  • I fount info about Volley have possibility to do it over RequestFuture. What do you recommend, use Volley or OkHTTP more stable for this kind of task? – Yevhen Mar 16 '17 at 16:01

2 Answers2

0

Sounds like you are trying to do this -

public class InitSettings_Task1 extends AsyncTask<Void, Void, Integer>  {
  @Override
  protected Integer doInBackground(Void... params) {
    request1result = request1;


    return result;
  }

  @Override
  protected void onPostExecute(Integer result) {
    //do something with result
    if (request1result) {
      result = new InitSettings_Task2().execute(httprequest2);
    } else {
      result = new InitSettings_Task2().execute(httprequest3); 
    }  

  }
}

public class InitSettings_Task2 extends AsyncTask<Void, Void, Integer>  {


   @Override
   protected Integer doInBackground(Void... params) {
      return result;
   }

   @Override
   protected void onPostExecute(Integer result) {
   //do what you want with result ?  
   }
}

But I would advise you against this. Its better to do this using frameworks like RxJava or even EventBus which are better suited for this scenario.

karthik prasad
  • 738
  • 7
  • 15
0

I have realized it with OkHTTP library. Thank's "Selvin" for right direction )

Yevhen
  • 791
  • 9
  • 24