我需要知道如何暂停代码执行,直到我的移动服务查询完成。我得到一个空指针异常,因为代码试图在查询完成之前访问查询数据。
---Code---
mEmployeeTable.execute(new TableQueryCallback<Employee>() {
//get employees
...
});
//In this activity i attempt to use the info loaded from the query above
//however since the query has not completed i get null pointer exception
startActivity(intent);
答案 0 :(得分:1)
只有在收到回调时才需要启动活动,类似于下面的代码:
mEmployeeTable.execute(new TableQueryCallback<Employee>() {
@Override
public void onCompleted(List<Employee> employees, int count, Exception exception, ServiceFilterResponse response) {
if (exception != null) {
// error happened during query, deal with it appropriately
} else {
// store the loaded employees somewhere
startActivity(intent);
}
}
});