1

现在我已经尝试了 2 个功能第一个(如下),工作并且我在启动此活动的活动中获取数据:

private void updateView() {
    Session session = Session.getActiveSession();
    if (session.isOpened()) {
        if (first) {
            if (session.getAccessToken() != null) {
                LogService.log("session", "session.getAccessToken(): " + session.getAccessToken());
            }
            Intent result = new Intent();
            result.putExtra("FB_DATA", new String[] { "1", "2", "userNume", "userPrenume" });
            FacebookLoginPage.this.setResult(Activity.RESULT_OK, result);
            FacebookLoginPage.this.finish()
            first = false;
        }
    }
}

现在是几秒钟,从 facebook 获取数据,然后将其发送到调用意图的处理程序。这总是关闭应用程序。正在等待结果的活动的 onDestroy 方法已关闭,我不明白为什么:

  private void updateView() {
    Session session = Session.getActiveSession();
    if (session.isOpened()) {
        if (first) {
            if (session.getAccessToken() != null) {
                LogService.log("session", "session.getAccessToken(): " + session.getAccessToken());
            }
            Request.executeMeRequestAsync(session, new GraphUserCallback() {
                @Override
                public void onCompleted(final GraphUser user, Response response) {
                    handler.sendMessage(handler.obtainMessage(1, user));
                }
            });
            first = false;
        }
    }
}

Handler handler = new Handler() {

    @Override
    public void handleMessage(Message msg) {
        GraphUser user = (GraphUser) msg.obj;
        if (user != null) {
            LogService.log("user email", "User=" + user);
            String userEmail = (String) user.getProperty("email");
            String id = (String) user.getId();
            String userNume = (String) user.getLastName();
            String userPrenume = (String) user.getFirstName();
            LogService.log("user email", userEmail + "||name: " + userNume + "|| prenume: " + userPrenume + "|| password: " + id);
            Intent result = new Intent();
            result.putExtra("FB_DATA", new String[] { id, userEmail, userNume, userPrenume });
            FacebookLoginPage.this.setResult(Activity.RESULT_OK, result);
        } else {
            FacebookLoginPage.this.setResult(Activity.RESULT_CANCELED);
        }
        System.out.println("----------------1");
        FacebookLoginPage.this.finish();
        System.out.println("----------------2");

    }
};

现在 logcat 会这样说(我已经更改了电子邮件、姓名、名字和密码):

03-14 12:11:29.301: I/user email(7119): email@yahoo.com||name: Name|| prenume: FirstName|| password: PASSWORD
03-14 12:11:29.301: I/System.out(7119): ----------------1
03-14 12:11:29.305: I/System.out(7119): ----------------2
03-14 12:11:29.313: I/Launcher(2610): onResume(). mIsNewIntent : false
03-14 12:11:29.313: I/Launcher(2610): onResume() ended
03-14 12:11:29.321: I/Launcher(2610): onWindowFocusChanged(true)
03-14 12:11:29.395: I/System.out(7119): ---------------LoginActivity.onDestroy()

我不明白 logcat 的最后 4 行是什么。带有 I/Launcher 的不是我的代码。最后一行,是调用此活动的活动的 ondestroy 方法,StartActivityForResult它不应该关闭,至少在进入OnActivityResult函数之前不应该关闭。

4

0 回答 0