Android HttpURLConnection only working with 3g not with wlan
<p>I am facing this weird problem with my android app. I have set up an AsyncTaskLoader to fetch data from an api to my app, and get the data parsed and displayed. This does work while the app is running under 3g mode. But, when I switch to WLAN, the same does not work. In some cases, it takes a long time (about 5 minutes, which is a long time ) to connect. I have narrowed it down to the following piece of code.</p>

<pre><code>URL url = new URL("http://example_site.com");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
Log.d("Connection", "Set Up Complete"); 
urlConnection.connect(); //This is the portion that I have narrowd down to.
Log.d("Connection", "connected");
InputStream inputStream = urlConnection.getInputStream();
StringBuffer buffer = new StringBuffer();
</code></pre>

<p>What are the causes of this particular problem, and how can I resolve it? My minimum sdk version is 15, and target to 24. </p>

<p>Edit:- Here is the permissions I gave in manifest just in case .</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="example.com.testapp"&gt;

    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
    &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
..

&lt;/manifest&gt;
</code></pre>