Sarah Stevens
Sarah Stevens

Reputation: 231

Send String into AsyncTask

How can I pass a variable into a AsyncTask like you would a function? I'd like to do what with the var httpLink

private class getinternetData extends AsyncTask<String, Void, String>{

    @Override
    protected String doInBackground(String... params) {
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(httpLink);
        try{
            //message.setText("333");
            HttpResponse response = httpclient.execute(httpget);
            //message.setText("444");
            StatusLine statusLine = response.getStatusLine();
            int statusCode = statusLine.getStatusCode();
            if(statusCode == 200){
                return "Could connect";
            }else
                return "Couldn't connect";
        }catch(Exception e){
            return e.toString();
        }


    }

Upvotes: 0

Views: 30

Answers (1)

marcinj
marcinj

Reputation: 49986

You call execute with parameter:

new getinternetData().execute("My string param");

then your httpLink is params[0]

Upvotes: 1

Related Questions