나는 AsyncTask
을 실행하기 위해 노력하고 있지만, 때 시작하고 doInBackground
마무리 (값이 반환)가 OnPostExecute
를 생략하고 내가 OnPostExecute
의 값을 변경하기 전에, 그래서 난 'if condition
를 실행하려고, 아래의 코드 requestTask2.execute()
를 실행 AsyncTask
널 가져 왔어.Android에서 OnPostExecute가 끝날 때까지 기다리는 방법은 무엇입니까?
나 코드로 설명하자 내가 if
조건 작품 전에 OnPostExecute
기다릴 수있는 방법
public void onClick(DialogInterface dialog,int id) {
Intent gt = new Intent(MainActivity.this, favorite.class);
String password = userInput.getText().toString();
String kadi = userInput2.getText().toString();
RequestTask2 requestTask2 = new RequestTask2();
requestTask2.execute("http://www.example.com/androfav/?fav2="+kadi+":"+password).get();
if (asd2[0][0]!=null && asd2[1][0]!=null) {
// This if condition works before on Post Excecute and it is causing the problem.
if (asd2[0][0].equals(password) && asd2[1][0].endsWith(kadi)) {
// Codes
}}
class RequestTask2 extends AsyncTask<String, String, String> {
private ProgressDialog dialog = new ProgressDialog(MainActivity.this);
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog.setMessage("Diziler Yükleniyor \n Lütfen Bekleyin...");
dialog.show();
dialog.setCancelable(false);
}
@Override
protected String doInBackground(String... uri2) {
HttpClient httpclient2 = new DefaultHttpClient();
HttpResponse response2;
String responseString2 = null;
try {
response2 = httpclient2.execute(new HttpGet(uri2[0]));
StatusLine statusLine2 = response2.getStatusLine();
if (statusLine2.getStatusCode() == HttpStatus.SC_OK) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response2.getEntity().writeTo(out);
out.close();
responseString2 = out.toString();
} else {
// Closes the connection.
response2.getEntity().getContent().close();
throw new IOException(statusLine2.getReasonPhrase());
}
} catch (ClientProtocolException e) {
// TODO Handle problems..
} catch (IOException e) {
// TODO Handle problems..
}
return responseString2;
}
@Override
protected void onPostExecute(String result2) {
super.onPostExecute(result2);
try {
JSONArray jsonResponse2 = new JSONArray(result2);
asd2 = new String[3][jsonResponse2.length()];
//............................... Codes
dialog.dismiss();
}
}
합니다. 희망은 나 자신을 이해할 수 있습니다. 미리 감사드립니다.
답장을 보내 주셔서 감사합니다. 나는 내가 어떻게 보지 못했는지 모른다. 그것은 아주 잘 작동합니다. – fthopkins
@ user3583237 http://developer.android.com/reference/android/os/AsyncTask.html#get(). 나는이 실수를하게 한 asynctask의 사용을 오해했다고 생각합니다. – Raghunandan
예, AsynTask 프로세스를 오해했는데, 이제는 이해했습니다. 다시 감사합니다. – fthopkins