2014-07-23 8 views
0

Azure Mobile Services에서 작업 중입니다. Id 목록에 따라 테이블에서 이메일을 받아야합니다. ID 목록을 반복하고 각 항목을 가져 와서 특정 항목을 테이블에서 가져 오는 메소드가 있습니다. 그러나 everithing은 onComplete 전에 실행됩니다. 내 코드 :작업 완료 후 코드 실행 Azure 모바일 서비스 및 Android

private ArrayList<String> administratorsEmail = new ArrayList<String>(); 

public boolean getAdminsEmail(List<String> adminList) 
{ 

    for(String ids : adminList) 
    { 
     UsersTable.lookUp(ids, new TableOperationCallback<Users>() 
     { 
      public void onCompleted(Users entity, Exception exception, ServiceFilterResponse response) 
      { 
       if (exception == null) 
       { 
        administratorsEmail.add(entity.getEmail()); 
       } 
      } 
     }); 
    } 

    //CODE HERE EXECUTES BEFORE ONCOMPLETE 
} 

administratorsEmail 목록을 작성해야합니다. 목록 이 완전히 채워진 후 일부 코드를 실행해야합니다. 그러나 루프보다 같은 시간에 코드를 실행하기 때문에 onComplete 메서드에 코드를 넣을 수 없습니다.

언제 OnCompleted가 완료되었는지 알아야합니다. 어떤 몸이라도 더 좋은 생각이나 도움을 줄 수 있습니까?

감사합니다.

답변

1

처리 할 레코드의 양에 대해 int counter을 만들고 counter == totalRecords 코드를 실행할 수 있습니다.

public boolean getAdminsEmail(List<String> adminList) 
{ 
int counter = 0; 
int totalRecords = adminList.length(); 

for(String ids : adminList) 
{ 
    UsersTable.lookUp(ids, new TableOperationCallback<Users>() 
    { 
     public void onCompleted(Users entity, Exception exception, ServiceFilterResponse response) 
     { 
      if (exception == null) 
      { 
       administratorsEmail.add(entity.getEmail()); 
       if (++counter == totalRecords) afterCompleted(); 
      } 
     } 
    }); 
} 

} 
private void afterCompleted() {... 
+0

고맙습니다! @SZH 이것을 시도하고 알려 드리겠습니다. 당신의 도움을 주셔서 감사합니다!! – josher932

관련 문제