android: How to use asyncTask in Rest Web service?
<p>I am creating apps in android in that I have login logout activity, Multilistview activity which data coming from rest web service. here problem is that when calling webservice from login activity I get error the networkonmainthreadexception then i searched on goggle about that exception, somebody said on stack overflow use AsyncTask in your code for seperation thread and I implemented asynctask in my code but not working. i am totally confusing how to use asynctask and I want to add asynctask in following code. I provide code without asynctask which i did. can anybody to help me how to exactly use asynctask when calling webservice. </p>

<p>following is the get data from edit text call function</p>

<pre><code>UserFunctions userFun = new UserFunctions();

        if ((username.trim().length() &gt; 0)&amp;&amp;(userpsw.trim().length() &gt; 0)) {

            JSONObject json = userFun.loginUser(username, userpsw);
            .
                        .
                        .
</code></pre>

<p>following is the function class  </p>

<pre><code>public JSONObject loginUser(String userEmail, String userPsw) {

        List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
        params.add(new BasicNameValuePair("tag", login_tag));
        params.add(new BasicNameValuePair("email", userEmail));
        params.add(new BasicNameValuePair("password", userPsw));
        JSONObject json = jsonParser.getJsondataFromUrl(params);
       //Log.d("tag", json.toString());
        return json;
    }
</code></pre>

<p>following is the actual webservice class</p>

<pre><code>public void getJsondataFromUrl(List&lt;NameValuePair&gt; params) {

     {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(params));

        HttpResponse httpResp = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResp.getEntity();
        inStream = httpEntity.getContent();
        //Log.d(tag, inStream.toString());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader bufferReader = new BufferedReader(new InputStreamReader
                (inStream, "iso-8859-1"), 8);
        StringBuilder  strBuilder = new StringBuilder();
        String line = null;
        while ((line = bufferReader.readLine()) != null) {
            strBuilder.append(line + "n");
        }
        inStream.close();
        json = strBuilder.toString();
        //Log.d("JSON", json);
    } catch (Exception e) {
        e.printStackTrace();
    } 
    // try parse the string to a JSON object
    try {
        jsonObj = new JSONObject(json);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return jsonObj;*/
}
</code></pre>

<p>Thanks in advance</p>
