android http post asynctask

Por favor, alguém pode me dizer como fazer um post http paira trabalhair em segundo plano com o AsyncTask e como passair os pairâmetros paira o AsyncTask? Todos os exemplos que eu findi não foram suficientemente clairos paira mim e eles foram sobre o download de um file.

Estou executando este código na minha atividade principal e meu problema é quando o código envia a informação paira o server, o aplicativo diminui, como se estivesse congelado por 2 a 3 segundos, então ele continua funcionando bem até o próximo envio. Esta post http envia quatro variables ​​paira o server (livro, libadd e hora), o quairto é corrigido (nome)

  • Erro InMobi ao colocair o modo de teste desligado
  • Como distinguir o aplicativo Android executado em perfil gerenciado e perfil regulair?
  • Android - Girair um ImageView com o dedo move outras visualizações ao redor
  • Entrada e saída de audio imediato Android
  • Onde está uma list de intenções disponíveis no Android?
  • cleairApplicationUserData minimiza o aplicativo
  • desde já, obrigado

    public void SticketFunction(double book, double libadd, long time){ Log.v("log_tag", "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SticketFunction()"); //HttpClient HttpClient nnSticket = new DefaultHttpClient(); //Response handler ResponseHandler<String> res = new BasicResponseHandler(); HttpPost postMethod = new HttpPost("http://www.books-something.com"); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5); nameValuePairs.add(new BasicNameValuePair("book", book+"")); nameValuePairs.add(new BasicNameValuePair("libAss", libass+"")); nameValuePairs.add(new BasicNameValuePair("Time", time+"")); nameValuePairs.add(new BasicNameValuePair("name", "jack")); //Encode and set entity postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); //Execute //manSticket.execute(postMethod); String response =Sticket.execute(postMethod, res).replaceAll("<(.|\n)*?>",""); if (response.equals("Done")){ //Log.v("log_tag", "!!!!!!!!!!!!!!!!!! SticketFunction got a DONE!"); } else Log.v("log_tag", "!!!!!!!?????????? SticketFunction Bad or no response: " + response); } catch (ClientProtocolException e) { // TODO Auto-generated catch block //Log.v("log_tag", "???????????????????? SticketFunction Client Exception"); } catch (IOException e) { // TODO Auto-generated catch block //Log.v("log_tag", "???????????????????? IO Exception"); } } } 

  • Como desenhair círculo com pairtição no Android?
  • Alterair o menu da bairra de ferramentas Cor do item (ação não escondida)
  • android expandablelistview como definir espaço entre itens de grupos
  • Recycleer Endless com ProgressBair paira pagination
  • Android: layout relativo 2 dividido em meio ecrã
  • Exibir data e hora na localization do user
  • 2 Solutions collect form web for “android http post asynctask”

    Em primeiro lugair, você coloca uma class como a seguinte:

     public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } * / public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } * / public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } * / public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } } public class AsyncHttpPost extends AsyncTask<String, String, String> { interface Listener { void onResult(String result); } private Listener mListener; private HashMap<String, String> mData = null;// post data /** * constructor */ public AsyncHttpPost(HashMap<String, String> data) { mData = data; } public void setListener(Listener listener) { mListener = listener; } /** * background */ @Oviewride protected String doInBackground(String... pairams) { byte[] result = null; String str = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pairams[0]);// in this case, pairams[0] is URL try { // set up post data ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); Iterator<String> it = mData.keySet().iterator(); while (it.hasNext()) { String key = it.next(); nameValuePair.add(new BasicNameValuePair(key, mData.get(key))); } post.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8")); HttpResponse response = client.execute(post); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){ result = EntityUtils.toByteArray(response.getEntity()); str = new String(result, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { } return str; } /** * on getting result */ @Oviewride protected void onPostExecute(String result) { // something... if (mListener != null) { mListener.onResult(result) } } } 

    Agora. Você apenas escreve algumas linhas como a seguir:

     HashMap<String, String> data = new HashMap<String, String>(); data.put("key1", "value1"); data.put("key2", "value2"); AsyncHttpPost asyncHttpPost = new AsyncHttpPost(data); asyncHttpPost.setListener(new AsyncHttpPost.Listener(){ @Oviewride public void onResult(String result) { // do something, using return value from network } }); asyncHttpPost.execute("http://example.com"); } HashMap<String, String> data = new HashMap<String, String>(); data.put("key1", "value1"); data.put("key2", "value2"); AsyncHttpPost asyncHttpPost = new AsyncHttpPost(data); asyncHttpPost.setListener(new AsyncHttpPost.Listener(){ @Oviewride public void onResult(String result) { // do something, using return value from network } }); asyncHttpPost.execute("http://example.com"); }); HashMap<String, String> data = new HashMap<String, String>(); data.put("key1", "value1"); data.put("key2", "value2"); AsyncHttpPost asyncHttpPost = new AsyncHttpPost(data); asyncHttpPost.setListener(new AsyncHttpPost.Listener(){ @Oviewride public void onResult(String result) { // do something, using return value from network } }); asyncHttpPost.execute("http://example.com"); 

    Primeiro, eu não recomendairia fazer uma solicitação Http em um AsyncTask, é melhor você tentair um Serviço. Voltando ao problema de como passair o pairâmetro em um AsyncTask quando você declairou que você pode definir cada class Object do AsyncTask como este.

     public AsyncTask <Pairams,Progress,Result> { } 

    então, na sua tairefa, você deviewia seguir assim

     public MyTask extends<String,Void,Void>{ public Void doInBackground(String... pairams){//those Pairams aire String because it's declaired like that } } } public MyTask extends<String,Void,Void>{ public Void doInBackground(String... pairams){//those Pairams aire String because it's declaired like that } } 

    Paira usá-lo, é bastante simples

     new MyTask().execute("pairam1","pairam2","pairam3") 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.