Passing parameters from Activity to doInBackground method, Async Task
<p>I'm trying to pass a variable "chartUrl" from JsonActivity to the doInBackground method as shown below. I've tried to change the arguments but that did not work. Does anyone know how to do this?</p>

<p>Thanks in advance</p>

<p>Code :</p>

<p>public class JsonActivity extends ListActivity{</p>

<pre><code> private ProgressDialog progressDialog;

    // JSON Node names

    private static final String TAG_RANK = "rank";
    private static final String TAG_NAME = "name";
   String chartUrl;

    String[] urlNames = new String[] { 
            "myurls"

            };

 // chartItemList holds the chart items 
    ArrayList&lt;HashMap&lt;String, String&gt;&gt; chartItemList = new ArrayList&lt;HashMap&lt;String, 
        String&gt;&gt;();
    JsonParser Parser = new JsonParser();

    JSONArray chartItems = null;

    /** Called when the activity is first created. */    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.listlayout);

      //Get the bundle from other activity
        Bundle bundle = getIntent().getExtras();

        //Extract chart index from the bundle
        int chartIndex = bundle.getInt("chartIndex");
        String chartUrl = urlNames[chartIndex]; 


        //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(chartUrl);

            String rank;

            String name;

            try{

            chartItems = new JSONArray(json);

            JSONObject json_data=null;

             for(int i=0;i&lt;chartItems.length();i++){

                json_data = chartItems.getJSONObject(i);
                rank=json_data.getString("rank");
                name=json_data.getString("name");


                 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);

                 // adding HashMap to ArrayList
                    chartItemList.add(hashMap);

             }


              ;
            }

            catch (JSONException e) {
                e.printStackTrace();
            }

            runOnUiThread(new Runnable() {
                public void run() {
                     System.out.println(chartItemList);

                  //updates the list view with the parsed items
                    ListAdapter adapter = new SimpleAdapter(JsonActivity.this, chartItemList,
                            R.layout.list_item,
                            new String[] {TAG_RANK,TAG_NAME, }, new int[] 

                         {R.id.rank ,R.id.name});
                    setListAdapter(adapter);
                }
            });
            return null;
        }

        //Removes the progress dialog when the data has been fetched
        protected void onPostExecute(String args) {
            progressDialog.dismiss();
        }
    }


  }
</code></pre>
