现在我尝试了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获取数据,然后将其发送到调用intent的处理程序。这总是关闭应用程序。正在等待结果的活动的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的不是我的代码。最后一行是使用StartActivityForResult
调用此活动的活动的ondestroy方法。这不应该关闭,至少在进入OnActivityResult
函数之前不会关闭。