AnsyncTask to open web page
<p>i am trying to use the Asynctask method to fetch data from a web server.</p>

<p>I have the following code.</p>

<pre><code>package com.example.myfirstapp;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class FetchData extends Activity {
private TextView textView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fetch_data);
    textView = (TextView) findViewById(R.id.TextView1);


    Intent intent = getIntent();
    String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
}

    private class DownloadWebPageTask extends AsyncTask&lt;String, Void, String&gt; {
        @Override
        protected String doInBackground(String... urls) {
          String response = "";
          for (String url : urls) {
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            try {
              HttpResponse execute = client.execute(httpGet);
              InputStream content = execute.getEntity().getContent();

              BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
              String s = "";
              while ((s = buffer.readLine()) != null) {
                response += s;
              }

            } catch (Exception e) {
              e.printStackTrace();
            }
          }
          return response;
        }

        @Override
        protected void onPostExecute(String result) {
          textView.setText(result);
        }
      }

      public void readWebpage(View view) {
        DownloadWebPageTask task = new DownloadWebPageTask();
        task.execute(new String[] {message});

}



}
</code></pre>

<p>My problem is this FetchData Activity in turn has to receive a data from MainActivity.
I have used intent to do so. Now, the intent I am using here, has the data from the MainActivity. This message contains the URL of the web server. I just need to use the message to obtain the results from web page.
I want to pass this message to the task.execute method so that it can return me the web page. How should I do it.?</p>
