【问题标题】:Best way to do several calls to http get request?对http get请求进行多次调用的最佳方法?
【发布时间】:2021-06-22 02:43:42
【问题描述】:

从我的 MainActivity 执行多个 http-get-request 调用(HttpURLConnection 执行)的最佳方法是什么?

我应该这样做:

    HttpGetRequest getRequest1 = new HttpGetRequest(); // Instantiate new class instance
    AsyncTask<String, Void, String> result1 = getRequest.execute(parameters1);
    HttpGetRequest getRequest2 = new HttpGetRequest(); // Instantiate new class instance
    AsyncTask<String, Void, String> result2 = getRequest.execute(parameters2);

... 或:

    HttpGetRequest getRequest = new HttpGetRequest(); // Instantiate new class instance
    AsyncTask<String, Void, String> result1 = getRequest.execute(parameters1);
    result2 = getRequest.execute(parameters2);

我想第二个选项是最好的,对吗?

【问题讨论】:

    标签: java android android-asynctask httprequest


    【解决方案1】:

    经过多次(不)成功的尝试,我得出的结论是,最好的方法是为每个请求创建一个新的 HttpGetRequest(),所以首选!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      • 2021-02-25
      • 2015-10-02
      • 2018-05-21
      • 2013-06-01
      • 2023-03-08
      • 1970-01-01
      相关资源
      最近更新 更多