0

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 内では動作しなくなります。ボタンクリックでサービスを開始しています。

4

1 に答える 1

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();
于 2014-04-13T13:04:43.170 に答える