0

I've been trying to learn to to use Android SDK and have encountered my first issue of trying to send information to a database. My first though was to use POST in Android and send it to a PHP script. However every tutorial or example I've found has been in a version of Android lower than 3.0 meaning they don't use AsyncTask and use Activity when extending their class. I am unsure how to write this code using ASyncTask and would like some advice or an example on how to do so, allowing it to work in Android 3.0 and onwards. Basically I want to be able to send variables to my php file on my website using Android Emulator.

Thanks for any help.

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
oliveroneill
  • 858
  • 9
  • 13

1 Answers1

0

Just copy and paste your HttpPost code into the AsyncTask's doInBackground method. You can notify the UI for progress updates using onProgressUpdate, and you can notify the UI when the task is completed in onPostExecute.

See this post for more information on how to implement the request (the code in the post performs an HttpGet request, so translating the code to use a HttpPost request instead should be simple).

And by the way, you should still use an AsyncTask to perform these kinds of requests on pre-HoneyComb devices. A lot of tutorials online do this incorrectly... just remember that you should always perform lengthy operations on a separate Thread, and network connections should always be considered to be potentially long-running operations (since you never know how long they will take).

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250