Getting data from Server too slow ? (Android)
<p>I am trying to populate <code>RecyclerView</code> by the list of transactions i get from the server . but unless i put a <code>Thread.sleep(7000)</code> , it won't populate .
Does it take this much time to get data from server side ?  If yes , Is there any faster alternative ?</p>
<p>or is getting the string from <code>json</code> response and adding object to list is time consuming ? because this sleep is just working for adding 5 rows in list. when i try to run loop for whole number of rows i don't get any data .</p>
<p>My host is <a href="http://www.pythonanywhere.com" rel="nofollow noreferrer">PythonAnywhere</a> .
API response is in <code>json</code> and has around 400 records :</p>
<p><a href="http://sairav.pythonanywhere.com/getTransaction" rel="nofollow noreferrer">http://sairav.pythonanywhere.com/getTransaction</a></p>
<p>Using :</p>
<blockquote>
<p>Android Asynchronous Http Client:::
compile 'com.loopj.android:android-async-http:1.4.9'</p>
</blockquote>
<pre><code>public List&lt;Transaction&gt; getTransactions(final boolean getAll) {
        Thread bgThread =null;
      
       final List&lt;Transaction&gt; trList=new ArrayList&lt;&gt;();
        RequestParams requestParams = new RequestParams();

        requestParams.put(&quot;uid&quot;, Profile.getCurrentProfile().getId());

        PAAPI.post(&quot;/getTransaction&quot;, requestParams, new JsonHttpResponseHandler() {

 @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray jsonArray) {
                
                Transaction trr = null;
                if (getAll) {
                   

                    for (int i = 0; i &lt; 5; i++) {

                        try {
                            //String a = jsonArray.getString(i);
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            //JSONArray arrayWithElements = jsonObject.toJSONArray(new JSONArray(new String[]{&quot;name&quot;,&quot;desc&quot;,&quot;amount&quot;,&quot;ttype&quot;,&quot;uid&quot;,&quot;ttime&quot;}));

                            trr =  new Transaction(context);

                            trr.uname = jsonObject.getString(&quot;uname&quot;);
                            trr.desc = jsonObject.getString(&quot;description&quot;);
                            trr.amount = jsonObject.getString(&quot;amount&quot;);
                            trr.type = jsonObject.getString(&quot;type&quot;);
                            trr.uid = jsonObject.getString(&quot;uid&quot;);
                            trr.date = jsonObject.getString(&quot;ttime&quot;);

                            trList.add(trr);
                           // Toast.makeText(context,&quot;size is bro :&quot;+trList.size(),Toast.LENGTH_SHORT).show();
                            if (i == 1) {
                   //             Toast.makeText(context, trr.uname + &quot;-&quot; + desc + &quot;-&quot; + trr.amount + &quot;-&quot; + trr.type + &quot;-&quot; + trr.uid + &quot;-&quot; + trr.date, Toast.LENGTH_SHORT).show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

                    // Do something with the response

                } 
 });
        try {
           Toast.makeText(context,&quot;sleeping bo&quot;,Toast.LENGTH_SHORT).show();

           Thread.sleep(7000);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

      //  Toast.makeText(context, &quot;listsize final is&quot; +  trList.size(), Toast.LENGTH_SHORT).show();
        return  trList;
    }



class PAAPI {
    protected static final String BASE_URL = &quot;http://sairav.pythonanywhere.com&quot;;

    private static AsyncHttpClient client = new AsyncHttpClient();

    public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
        client.post(getAbsoluteUrl(url), params, responseHandler);
    }

    public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
        client.post(getAbsoluteUrl(url), params, responseHandler);
    }

    private static String getAbsoluteUrl(String relativeUrl) {
        return BASE_URL + relativeUrl;
    }
}
</code></pre>