title: Managing the background thread within Android application
body: <p>I currently have this class below which  parses json urls and loads images and texts into a listview with the help of the Lazy Adapter Class and background thread. </p>
  
  <p>Each list item consists of an image view and 2 text views.</p>
  
  <p>I want to create pop up boxes (alert dialog) for each of the generated list items. The alert dialog will have options which will call other applications. </p>
  
  <p>My question : </p>
  
  <p>Would it be wise to code this alert dialog functionality in this class? I'm worried that there is a lot of stuff currently being done in the background and it might affect the app's functionality. </p>
  
  <p>If not could anyone suggest another way to do it. thanks.</p>
  
  <p>Json Activity Class :</p>
  
  <pre><code>public class JsonActivity extends  SherlockActivity{
  
   private ProgressDialog progressDialog;
  
      // JSON Node names
  
  
     static final String TAG_NAME = "name";
     static final String TAG_IMAGEURL = "imageurl";
  
      ListView list;
      LazyAdapter adapter;
  
     String chartUrl;
  
      String[] urlNames = new String[] { 
              "urls..."
  
              };
  
   // chartItemList is the array list that holds the chart items 
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; chartItemList = new ArrayList&lt;HashMap&lt;String, 
          String&gt;&gt;();
  
      //Holds imageurls 
      ArrayList&lt;String&gt; imageurls = new ArrayList&lt;String&gt;();
  
  
      JsonParser Parser = new JsonParser();
   // JSONArray
      JSONArray chartItems = null;
  
      /** Called when the activity is first created. */    
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.chart);
  
          //Get the bundle 
          Bundle bundle = getIntent().getExtras();
  
          //Extract the data from the bundle
          int chartIndex = bundle.getInt("chartIndex");
          String chartUrl = urlNames[chartIndex]; 
  
          setTitle(bundle.getString("chartname"));
  
  
  
          //url from where the JSON has to be retrieved
          String url = chartUrl;
  
          //Check if the user has a connection
  
          ConnectivityManager cm = (ConnectivityManager) 
              getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo info = cm.getActiveNetworkInfo();
          if (info != null) {
              if (!info.isConnected()) {
                  Toast.makeText(this, "Please check your connection and try again.", 
               Toast.LENGTH_SHORT).show();
              }
  
              //if positive, fetch the articles in background
              else new getChartItems().execute(chartUrl);
          }
  
          //else show toast
          else {
              Toast.makeText(this, "Please check your connection and try again.", 
              Toast.LENGTH_SHORT).show();
          }
  
      }
  
  
      class getChartItems extends AsyncTask&lt;String, String, String&gt; {
  
          // Shows a progress dialog while setting up the background task
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              progressDialog = new ProgressDialog(JsonActivity.this);
              progressDialog.setMessage("Loading chart...");
              progressDialog.setIndeterminate(false);
              progressDialog.setCancelable(false);
              progressDialog.show();
          }
  
          //Gets the json data for chart items data and presents it in a list view
          @Override
          protected String doInBackground(String... args) {
  
          String json = Parser.getJSONFromUrl(args[0]);
              String imageurl;
          String rank;
          String name;            
          String url;
  
              try{
  
  
              chartItems = new JSONArray(json);
  
              JSONObject json_data=null;
  
               for(int i=0;i&lt;chartItems.length();i++){
  
                  json_data = chartItems.getJSONObject(i);
  
                  //Retrieves the value of the name from the json object
  
                  name=json_data.getString("name");
  
                  //Retrieves the image url for that object and adds it to an arraylist
                  imageurl=json_data.getString("imageurl");
                  //imageurls.add(imageurl);
  
                   HashMap&lt;String, String&gt; hashMap = new HashMap&lt;String, String&gt;();
                   // adding each child node to HashMap key =&gt; value
                   //hashMap.put(TAG_RANK, rank);
                   hashMap.put(TAG_NAME, name);
                   hashMap.put(TAG_IMAGEURL, imageurl);
  
  
                   // adding HashMap to ArrayList
                      chartItemList.add(hashMap);
  
               }
  
  
                ;
              }
  
              catch (JSONException e) {
                  e.printStackTrace();
              }
  
              runOnUiThread(new Runnable() {
                  public void run() {
  
  
                      list=(ListView)findViewById(R.id.list);
  
                       // Getting adapter by passing xml data ArrayList
                       adapter = new LazyAdapter(JsonActivity.this, chartItemList);
                       list.setAdapter(adapter);
  
                       // Click event for single list row
                       list.setOnItemClickListener(new OnItemClickListener() {
  
                           @Override
                           public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                   int position, long id) {
  
                           }
                       });
  
  
  
  
                  }
              });
              return null;
          }
  
          //Removes the progress dialog when the data has been fetched
          protected void onPostExecute(String args) {
              progressDialog.dismiss();
          }
      }
  </code></pre>
  
  <p>}</p>