我正在 IntentService 中执行一个简单的查询(fql)(通过单击按钮开始)。这是我的服务类的 onHandleIntent() 方法:
protected void onHandleIntent(Intent intent)
{
Global appState = ((Global)getApplicationContext());
System.out.println("inside the service now");
String uid=appState.uid[0];
System.out.println("uid ="+uid);
String fqlQuery = "SELECT uid, name, online_presence, status FROM user WHERE uid="+uid+" ";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
System.out.println(session);
Request request = new Request(session, // starting of innerclass
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
//Log.i(TAG, "Result: " +response.toString() ); //response.toString()
GraphObject graphObject = response.getGraphObject();
// String s = textViewResults.getText().toString();
if (graphObject != null) {
JSONObject jsonObject = graphObject.getInnerJSONObject();
try {
JSONArray array = jsonObject.getJSONArray("data");
for (int j = 0; j < array.length(); j++) { // always array.length()=1, loop will run jst 1 time
JSONObject object = (JSONObject) array.get(j);
System.out.println("inside inner class now");
System.out.println("id = " +object.get("uid").toString() );
System.out.println("name = "+object.get("name").toString());
System.out.println("op ="+object.get("online_presence").toString()+"niraj");
name=object.get("name").toString();
}
} catch (JSONException e) {
e.printStackTrace();
}
} // end of if block
} // end of onCompleted method
});
// Thread.currentThread().sleep(10000);//sleep for 1000 ms
Request.executeBatchAsync(request);
System.out.println("outsise the inner class ____ name : "+name);
}
问题是内部类中的代码段(从请求开始)没有被执行。对于上面的代码,我得到以下输出:
07-26 17:21:09.105: I/System.out(1541): inside the service now
07-26 17:21:09.105: I/System.out(1541): uid =100002621905500
07-26 17:21:09.136: I/System.out(1541): {Session state:OPENED, token:{AccessToken
token:ACCESS_TOKEN_REMOVED permissions:[user_likes, user_status,
friends_online_presence, user_online_presence]}, appId:"my app id"}
07-26 17:21:09.206: I/System.out(1541): outsise the inner class ____ name : null
我没有得到错误是什么。甚至日志也没有显示任何错误。请帮忙。