'HTTPPOST'에 해당되는 글 1건

  1. 2012.11.23 [안드로이드]서버와 통신하기 HttpPost, Loading처리
programing2012. 11. 23. 17:28
로딩화면 그냥 보여주는건 누구나할수있는데 내가 원하는타이밍에 마춰하는건 쉽지 않습니다.? 나한테만 어려울수도...
아래 참고하면 도움이 될수있습니다.

호출부 인자값은 정해주기 나름이며 처리부 protected Void doInBackground(String... urls)
urls에 하나씩 매칭이됩니다. urls[0],urls[1]....이런식이죠...

 
//호출부...
 new PutLocation().execute("1", uniqueId, "00000");

 //서버에 값을 전송하고 정상적으로 처리될때까지 로딩화면을 보여준다.
 //정상적으로 처리가안될경우에 response값을 비교하여 에러처리를 한다.
 //처리부...
 protected class PutLocation extends AsyncTask {  //이거 이상하네요.. 알아서..들....
  private String Error = null;
  private Dialog Dialog = new Dialog(Location.this, R.style.ProgressDialog);
  HttpResponse response;
  
  // - 결과값 받기전까지 보여줄 메시지
  protected void onPreExecute() {
   Dialog.setContentView(R.layout.progressbar);
   Dialog.show(); // 로딩 시작
  }

  // - 결과값 받기
  protected Void doInBackground(String... urls) {
   StringBuffer buffer = new StringBuffer();
   try {
    buffer.append("platformId").append("=").append(urls[0]).append("&");
    buffer.append("uniqueId").append("=").append(urls[1]).append("&");
    buffer.append("locationId").append("=").append(urls[2]);
    HttpGet get = new HttpGet("URL");

    HttpClient client = new DefaultHttpClient();

    response = client.execute(get);

   } catch (ClientProtocolException e) {
    Error = "ClientProtocolException";
    cancel(true);
   } catch (IOException e) {
    Error = "IOException";
    cancel(true);
   } catch (Exception e) {
    Error = "Exception";
    cancel(true);
   }

   //return을 처리하면 onPostExecute에서 return값을 받아 결과값을 처리할수있다.
   return null;
  }

  // 결과값 처리
  protected void onPostExecute(Void unused) {
   Dialog.dismiss(); // 로딩종료
  }
 }
Posted by 부르마