*Create a subclass of AsyncTask like so:*

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         int count = urls.length;
         long totalSize = 0;
         for (int i = 0; i < count; i++) {
             totalSize += Downloader.downloadFile(urls[i]);
             publishProgress((int) ((i / (float) count) * 100));
             // Escape early if cancel() is called
             if (isCancelled()) break;
         }
         return totalSize;
     }

     protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
     }

     protected void onPostExecute(Long result) {
         showDialog("Downloaded " + result + " bytes");
     }
 }



*Execute it like so:*

new DownloadFilesTask().execute(url1, url2, url3);


On Monday, December 17, 2012 9:13:18 AM UTC-6, Antonis Kanaris wrote:
>
> How use and call AsyncTask into my code for upload data?
>
>   
>
> List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);  //you 
> should put here your temp variable
> nameValuePairs.add(new BasicNameValuePair("temperature", String.valueOf(30)));
> HttpPost request = post("http://mysite.com/temperature.php";, nameValuePairs);
> DefaultHttpClient client = generateHttpClient();HttpResponse httpResponse = 
> client.execute(request);
>
> Where:
>
> public static DefaultHttpClient generateHttpClient(){
>         HttpParams params = new BasicHttpParams();
>         HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_CONNECTION);
>         HttpConnectionParams.setSoTimeout(params, TIMEOUT_SOCKET);
>         SchemeRegistry registry = new SchemeRegistry();
>         registry.register(new Scheme("http", 
> PlainSocketFactory.getSocketFactory(), 80));
>
>         try{
>
> KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
>         trustStore.load(null, null);
>
>         SSLSocketFactory sf = new EasySSLSocketFactory(trustStore);
>         sf.setHostnameVerifier(
>                SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
>         registry.register(new Scheme("https", sf, 443));
>     }catch (Exception e) {
>         e.printStackTrace();
>     }
> //      params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,             
> HttpVersion.HTTP_1_1);
>     ClientConnectionManager cm = new ThreadSafeClientConnManager(params, 
> registry);
>     DefaultHttpClient client = new DefaultHttpClient(cm, params);
>     client.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() { 
>         @Override 
>         public long getKeepAliveDuration(HttpResponse response, HttpContext 
>     context) { 
>             return 60; // seconds 
>         } 
>
>     }); 
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to