0

I'm developping and android application and in some point I need to get some vaue from my server. This server has a simple PHP script that just echo a value. In order to do it, that's what I do:

private static String executePHP(String URL) {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(URL);

    try {
    // Execute HTTP Post Request
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String response = httpclient.execute(httppost, responseHandler);

        return(response);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        return("");
    }
}

The method is static, because I call it upon an SMS arrives. Then the URL comes from the SMS text. From the broadcastReceiver I call:

MainActivity.executePHP(link);

I want the execution of the PHP to be on a background task.

I've been reading of AsyncTask but they need and instance, which I don't have.

What's the best way to do it?? Also, have in mind that the application may not be active right now.

I'll be happy if I can only Toast the result from the PHP executing on asyncTask (or other asyncrhonus thread).

Thanks you all!! Have a nice day!

sebasira
  • 1,739
  • 1
  • 22
  • 41

1 Answers1

0

Finally, this solve my question! Now I need to see how to handle no-internet-connection.

solution

Community
  • 1
  • 1
sebasira
  • 1,739
  • 1
  • 22
  • 41