Android post method in one class
<p>Hi I have this post method in every activity. How can I put this post into one class such that if error I will know? Otherwise, I will be parsing the error message as json.</p>

<pre><code>private boolean login(String username, String password) {
    TextView err = (TextView) findViewById(R.id.err);
    boolean status = false;
    String postData = "{\"Password\":\"" + password + "\",\"UserName\":\"" + username + "\"}";
    try {
        String domain = getString(R.string.domain);
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response;
        HttpPost httppost = new HttpPost(domain + "login");
        StringEntity se = new StringEntity(postData.toString(), "utf-8");
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httppost.setEntity(se);
        httppost.setHeader("Accept", "application/json");
        httppost.setHeader("Content-type", "application/json");
        response = httpclient.execute(httppost);
        if (response != null) {
            HttpEntity r_entity = response.getEntity();
            String json = EntityUtils.toString(r_entity);
            JSONObject jsonobj = new JSONObject(json);
            status = jsonobj.getBoolean("result"); 
        }


    } catch (Exception e) {
        err.setText(e.getLocalizedMessage());
    }
</code></pre>
