Weird NetworkOnMainThread exception
<p>I'm new to android, please halp.</p>

<p>This is a really simple scenario, there's an actionbar, and when a tab is selected, I need to send an http request to get an article list, when the response arrives, update a listview and here's where I got this exception. </p>

<p>I'm aware that I should isolate network operations from UI thread, so I implement the network functions in an AsyncTask class.</p>

<p>The most weird part is, before I try to get the article list, I have actually called a network function once to log in, and that just works fine, no exceptions! And guess what, if I replace the get article list call with log in call, it works fine, too. All the code are just the same, except the arguments differ.</p>

<p>Here's how I do it, since too many modules will use the network module, I use a static wrapper:</p>

<p>UI -> Static Factory -> New AsyncTask -> Response arrives -> Call Static callback function in Static Factory -> Call callback function in UI</p>

<p>AsyncTask doInBackground</p>

<pre><code>@Override
protected HttpResponse doInBackground(String... params) {
    // TODO Auto-generated method stub
    String uri = params[0];
    HttpGet get = new HttpGet(uri);
    try {
        return _client.execute(get);
    }
    catch(Exception e) {
        e.printStackTrace();
        return null;
    }   
}
</code></pre>

<p>AsyncTask post execute</p>

<pre><code>    @Override
    protected void onPostExecute(HttpResponse result) {
        //Do something with result
        if (result != null) {
            try {
                JSONObject json = FormJsonFromResponse();
                Command.OnTaskComplete(json);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }
</code></pre>

<p>static wrapper code:</p>

<pre><code>@Override
    public static void OnTaskComplete(JSONObject json) {
        // TODO Auto-generated method stub
        if(_callback != null) {
            _callback.OnCommandComplete(json);
        }
    }
</code></pre>

<p>Here's how I call asynctask in static wrapper:</p>

<pre><code>public static void LogIn(String user, String pass) {
    new NetworkTask().execute(_uriPrefix + login, _user, _pass);
}
</code></pre>
