我已經使用Sessions在我的Android應用程序中整合了Facebook。我有一個登錄活動,有一個Facebook登錄按鈕。我想在成功登錄Facebook後成爲另一個名爲MainActivity的活動,該應用程序在沒有任何錯誤或沒有進入MainActivity的情況下關閉。任何人都可以建議我在哪裏給代碼開始活動。這是我的代碼。如何在Android上成功登錄Facebook後再去另一個活動?
ImageButton buttonLoginLogout,bb;
Session.StatusCallback statusCallback = new SessionStatusCallback();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
buttonLoginLogout = (ImageButton)findViewById(R.id.imageButton1);
buttonLoginLogout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
onClickLogin();
}
});
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
}
}
updateView();
}
@Override
public void onStart() {
super.onStart();
Session.getActiveSession().addCallback(statusCallback);
}
@Override
public void onStop() {
super.onStop();
Session.getActiveSession().removeCallback(statusCallback);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Session session = Session.getActiveSession();
Session.saveSession(session, outState);
}
private void updateView() {
Session session = Session.getActiveSession();
}
});
Intent ik=new Intent(Login.this,MainActivity.class);
startActivity(ik);
} }
private void onClickLogin() {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
} else {
Session.openActiveSession(this, true, statusCallback);
}
}
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state, Exception exception) {
updateView();
}
}
}
in onPostExecute你可以開始你的主要活動... –
你知道代碼流嗎?只是調試它,你會知道在哪裏把你的代碼啓動另一個活動。 – Farhan