fatalaa

AsyncTask

Feb 15th, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package com.example.pc_szerviz;
  2.  
  3. import java.io.IOException;
  4.  
  5. import org.apache.commons.httpclient.HttpClient;
  6. import org.apache.commons.httpclient.methods.GetMethod;
  7.  
  8. import android.content.Context;
  9. import android.os.AsyncTask;
  10.  
  11. public class ConnectionTask extends AsyncTask<String, Void, String> {
  12.     HttpClient client;
  13.     GetMethod getMethod;
  14.     String response;
  15.    
  16.     @Override
  17.     protected String doInBackground(String... commands) {
  18.         client = new HttpClient();
  19.         getMethod = new GetMethod(commands[0]);
  20.         response = new String();
  21.         try {
  22.             client.executeMethod(getMethod);
  23.             response = getMethod.getResponseBodyAsString();
  24.             getMethod.releaseConnection();
  25.         } catch(IOException e) {
  26.             e.printStackTrace();
  27.         }
  28.         return response;
  29.     }
  30. }
  31.  
  32. //Így van meghívva
  33. public boolean updateUgyfelTabla(Ugyfel obj) {
  34.         String url = "http://teszt.tonsofdamage.hu/server/index.php?c=update&t=Ugyfel&d="
  35.                 +new Gson().toJson(obj, obj.getClass());
  36.     ConnectionTask conn = new ConnectionTask();
  37.     conn.execute(new String[]{url});
  38.     String jsonOfResponse = conn.response;
  39.     if(Integer.valueOf(jsonOfResponse) == 1) {
  40.         return true;
  41.     }
  42.     return false;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment