2013-07-23 2 views
0

Intentservice의 onHandleIntent() 메소드에서 간단한 fql 쿼리를 실행하고 있습니다. 문제는 무엇인지 알지 못하지만 쿼리 부분은 실행되지 않습니다. 여기에 내 onHandleIntent() 메서드가 있습니다.Android IntentService 관련 문제

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에서는 작동하지 않습니다. 나는 buttonclick에 서비스를 시작하고있다.

+0

오류를 먼저 catch해야합니다. 이 메서드는 약간의 오류를 던져야합니다. 메서드에서 try catch를 사용하고 오류를 catch하십시오. 그런 다음 문제를 해결할 수 있습니다. –

+0

'지금 서비스 내부에서 4444'만 인쇄되는 것을 의미합니까? – gunar

+0

아니요, 첫 번째 인쇄 명령문 만 실행됩니다. – user1872750

답변

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();