public class TestActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
restAPIAsyncTask async= new restAPIAsyncTask(getApplicationContext());
async.execute("Good");
try {
async.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
public class restAPIAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog pDialog = null;
Context aContext;
public restAPIAsyncTask(Context context) {
aContext = context;
pDialog = new ProgressDialog(aContext);
}
@Override
protected void onPreExecute() {
Log.d("Log", "onPreExecute");
pDialog.setMessage("Please Wait....");
pDialog.show();
}
@Override
protected Boolean doInBackground(String... params) {
String url = "http://example.com";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
postParams.add(new BasicNameValuePair("type", "all"));
postParams.add(new BasicNameValuePair("limit", "all"));
try {
httppost.setEntity(new UrlEncodedFormEntity(postParams));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
HttpResponse response = httpclient.execute(httppost);
Log.d("Log", "response:" + EntityUtils.toString(response.getEntity()));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
// if (pDialog != null)
// pDialog.dismiss();
}
}
}
아예 보이지 않고, onPostExecute에서 dismiss 주석을 해제하면 에러가 납니다.
뭐가 잘못된건까요??