onCompleted()
a のコールバック関数が終了するまで待機しようとしていますRequest
。ただし、 のメソッド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 として検索されます。どうすればこの問題を解決できますか?