신입 개발자입니다.. ㅠㅠ 프로그래스바를 넣어야하는데 막혔어요..
-- 구성 요약 --
Asynctask로 서버의 데이터를 json 으로 받아오게끔 구성하고 액티비티에서
NetworkService service = new NetworkService("?id=id&pw=password); // 쿼리스트링을넣고 생성
service.excute().get(); // 서버데이터가져옴
service.getReceiveMsg(); // 가져온 json데이터
-------------
이런식으로 쓰고있는데요..
onPreExcute에 프로그래스를 동작하게 하고싶은데 어떻게해야하나요?
public class NetworkService extends AsyncTask<String, Void, String> {
// receiveMsg : json리턴데이터
// domainStr : 도메인주소
private String receiveMsg, request, domainStr;
private JSONArray jsonArray;
private JSONObject jsonObject;
private ProgressBar mProBar;
private Context mContext;
// IP혹은 도메인 입력해두는 클래스
private Domain domain = new Domain();
@Override
protected void onPreExecute() {
// 어떻게..
}
// 생성자 : 요청URL을 가지고 들어옴
public NetworkService(String request) {
this.request = request;
}
// JSON Result 데이터 리턴 메소드
public String getReceiveMsg() {
return receiveMsg;
}
// JSONArray 리턴
// public JSONArray jsonReturn(){ return jsonArray; }
public JSONObject jsonObjectReturn() { return jsonObject; }
@Override
protected String doInBackground(String... params) {
URL url = null;
try {
// 도메인 http://192.168.0.71:8080/
domainStr = domain.getDomain();
String str;
url = new URL(domainStr+request);
System.out.println(domainStr+request);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
if (conn.getResponseCode() == conn.HTTP_OK) {
InputStreamReader tmp = new InputStreamReader(conn.getInputStream(), "UTF-8");
BufferedReader reader = new BufferedReader(tmp);
StringBuffer buffer = new StringBuffer();
while ((str = reader.readLine()) != null) {
buffer.append(str);
}
// String JSON 리턴
receiveMsg = buffer.toString();
System.out.println(receiveMsg);
reader.close();
conn.disconnect();
} else {
Log.i("통신 결과", conn.getResponseCode() + "에러");
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return receiveMsg;
}
}