Resuse of Async task code in my various file <p>I want to create an class file for Async task operation and from creating the object of that class file i want to access these method of async task with no of different class files with different parameters. </p> <p><strong>Methods of Async task include:-</strong></p> <p><strong>OnPreExecute()</strong>-Want to start progress dialog same for each class.</p> <p><strong>doInbackground()</strong>-Want to perform background operation(like getting data from server) means passing parameter different for each class. </p> <p><strong>onPostExecute()</strong>-Dismiss the progress dialog and update the UI differnt for each class.</p> <p>Nw i m writing the async task in my every class as inner class like following:-</p> <pre><code>class loaddata extends AsyncTask&lt;String, String, String&gt; { @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(AddNewLineitem.this); pDialog.setMessage("Loading Data. Please wait..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { } }); pDialog.show(); } @Override protected String doInBackground(String... params) { try { List&lt;NameValuePair&gt; params1 = new ArrayList&lt;NameValuePair&gt;(); JSONObject json = jparser.makeHttpRequest(url_foralldropdowns, "GET", params1); compoment = json.getJSONArray(COMPONENT_CODE); for (int i = 1; i &lt; compoment.length(); i++) { JSONObject c = compoment.getJSONObject(i); String code = c.getString(CODE); list_compoment.add(code); } } catch (Exception e) { e.printStackTrace(); } return null; } protected void onPostExecute(String file_url) { loadSpinnerData(); pDialog.dismiss(); } } </code></pre> <p>And JSON parser class is as follows:-</p> <pre><code>public class JSONParser { static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONParser() { } // function get json from url // by making HTTP POST or GET mehtod public JSONObject makeHttpRequest(String url, String method, List&lt;NameValuePair&gt; params) { // Making HTTP request try { // check for request method if (method == "POST") { // request method is POST // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } else if (method == "GET") { // request method is GET DefaultHttpClient httpClient = new DefaultHttpClient(); String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } // return JSON String return jObj; } } </code></pre> <p>And in oncreate() i call this and it works fine:-</p> <pre><code>new loaddata().execute(); </code></pre> <p>Please Help yourself..Thanks in advance</p>