我试图等到onCompleted()
我的回调函数 aRequest
完成。然而,总是在此之前返回的方法get()
就是RequestAsyncTask
这种情况。因此,在我的程序的进一步陈述中出现了问题。println
输出总是在数据库查询之后显示并且不相等null
。这是我的代码:
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
// show authendicated ui
Log.i(TAG, "Logged in...");
try {
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
MyApplication.userId = user.getId();
System.out.println("User id: " + MyApplication.userId);
}
}
}).executeAsync().get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
boolean isNewUser = !MyApplication.dbConnection.isUidRegistered(MyApplication.userId);
这会导致我的数据库查找null
为 uid。我怎么解决这个问题?