我在Intentservice的onHandleIntent()方法中运行一个简单的fql查询。不知道问题是什么,查询部分不会被执行。这是我的onHandleIntent()方法
protected void onHandleIntent(Intent intent)
{
System.out.println("inside service method now");
String fqlQuery = "SELECT uid, username, online_presence, status FROM user WHERE uid = 100001024732884";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
System.out.println("inside the service now 4444");
Log.i(TAG, "Result: " + response.toString());
}
});
Request.executeBatchAsync(request);
}
只打印第一个语句。
当我在MainActivity中放入相同的代码时,它工作正常,但在IntentService内部它停止工作。我正在按钮上启动服务。
答案 0 :(得分:0)
您的问题是,在调用回调之前,IntentService将被完成并销毁,因为它是异步运行的。不要使用回调来获取响应,而是尝试使用它。
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET);
Response response = request.executeBatchAndWait();