我有这个代码,
应该呼叫并等待
异步任务“getCreator”。
private String getcreator(String id) {
String creator = null;
Log.e("","entro proprio in getcreator "+ id);
if (id != null) {
String srt = "";
getCreator chn = new getCreator();
chn.execute(id, null, null);
try {
srt = chn.get();
Log.e("","predodo qulacosa da getcreator");
} catch (Exception e) {
Log.e("","exceltion in getcreator");
e.printStackTrace();
}
JSONObject jObject = null;
try {
jObject = new JSONObject(srt);
creator = jObject.getString("name");
} catch (JSONException e) {
// Json parse error usually
}
}
return creator;
}
但是 AsyncTask getCreator从不执行它的 doinbackground() !!!
public class getCreator extends AsyncTask<String, String, String> {
public String res;
@Override
protected void onProgressUpdate(String... progress) {
}
@Override
protected void onPostExecute(String result) {
}
@Override
protected String doInBackground(String... symbol) {
String result = "";
Log.e("","entro in getcreator"+ symbol[0]);
DefaultHttpClient client = new DefaultHttpClient();
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is
// established.
// The default value is zero, that means the timeout is not
// used.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams
.setSoTimeout(httpParameters, timeoutSocket);
client.setParams(httpParameters);
String srt = "";
String url = "http://graph.facebook.com/".concat(symbol[0]);
HttpGet getMethod = new HttpGet(url);
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
srt = client.execute(getMethod, responseHandler);
result = srt;
} catch (Throwable t) {
// Toast.makeText(getApplicationContext(),
// "Internet Problem", Toast.LENGTH_SHORT).show();
}
Log.e("","esco in getcreator");
return result;
}
}
请帮忙!!!!
准确地说: doInBackground() 甚至没有被执行....
定期调用 private String getcreator(String id) 方法,并生成其日志。
帮助!!!