title: OkHttp3 is returning timeout exception
body: <p>I am using okhttp3 as a networking library and Node-mongo as a back-end service.Sometimes when my app starts it shows timeout exception and when I close app and start it again then it fetches data from the server.There is no error in app but I want to know why timeout exception is showing.</p>
  
  <p>Below is my code in which I am showing data in listview.</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class Activity2 extends AppCompatActivity {
  
  ListView listView;
  List&lt;Data&gt; places;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_2);
  
      listView  = findViewById(R.id.listView);
      places = new ArrayList&lt;&gt;();
  
      final ProgressDialog prg = new ProgressDialog(Activity2.this);
      prg.setMessage("Loading...");
      prg.show();
  
      Log.d("OnCreate","Oncreate started");
  
      OkHttpClient client = new OkHttpClient();
  
      Request request = new Request.Builder().url("https://tiffino.herokuapp.com/test").build();
  
      client.newCall(request).enqueue(new Callback() {
  
          @Override
          public void onFailure(Call call, final IOException e) {
  
              prg.dismiss();
  
              runOnUiThread(new Runnable() {
                  @Override
                  public void run() {
                      Toast.makeText(getApplicationContext(),""+e.getMessage(),Toast.LENGTH_SHORT).show();
                  }
              });
          }
  
          @Override
          public void onResponse(Call call, final Response response) throws IOException {
  
              prg.dismiss();
  
              runOnUiThread(new Runnable() {
                  @Override
                  public void run() {
  
                      try {
                          JSONArray arr = new JSONArray(response.body().string());
  
                          for(int i = 0;i &lt; arr.length();i++){
  
                              JSONObject obj = arr.getJSONObject(i);
  
                              String str1 = obj.getString("Name");
  
                              Data data = new Data(str1);
  
                              places.add(data);
  
                          }
  
                          PlacesAdapter adapter=  new PlacesAdapter(places,getApplicationContext());
                          listView.setAdapter(adapter);
  
                      } catch (JSONException e) {
                          e.printStackTrace();
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
                  }
              });
          }
  
      });
  
     }
  } 
  </code></pre>
  
  <p><strong>PlacesAdapter.java</strong></p>
  
  <pre><code>public class PlacesAdapter extends ArrayAdapter&lt;Data&gt; {
  
  private List&lt;Data&gt;  places;
  private Context ctx;
  
  public PlacesAdapter( List&lt;Data&gt; places, Context ctx) {
      super(ctx,R.layout.places_row,places);
      this.places = places;
      this.ctx = ctx;
  }
  
  @NonNull
  @Override
  public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
  
      LayoutInflater inflater = LayoutInflater.from(ctx);
  
      View listView = inflater.inflate(R.layout.places_row,null,true);
  
      TextView txt = listView.findViewById(R.id.txt);
  
      Data data = places.get(position);
  
      txt.setText(data.getPlace());
  
      return listView;
  
    }
  }
  </code></pre>
  
  <p>How can I solve this?</p>