Android登录Facebook并开始新的活动

时间:2014-04-24 17:55:16

标签: android facebook android-facebook

我对如何在登录成功后开启新活动表示怀疑。

我做了这个教程:https://developers.facebook.com/docs/android/login-with-facebook

但是我想要一个有登录按钮的应用程序,登录后输入其他活动, 在本教程中,单击登录按钮后,将显示注销按钮 我不想出现退出按钮。

有人可以回答这个问题吗?

2 个答案:

答案 0 :(得分:1)

首先你可以用这样的forresult调用facebooklogin活动:

Intent myIntent = new Intent(this,FacebookActivity_Logon.class );  
startActivityForResult(myIntent,2000);

然后你可以在活动结果中调用另一个活动:

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);

     if(requestCode==2000)
     {  
        Intent myIntent = new Intent(login.this,another_activity.class);         
        startActivity (myIntent);
        finish(); //if you want to do not use this
     }
}

答案 1 :(得分:0)

Facebook SDK在内部加载您需要遵循完整说明的登录页面

初始化

private Session.StatusCallback statusCallback = new SessionStatusCallback();

点击事件调用

openActiveSession(this, true, statusCallback);

方法如下

public static Session openActiveSession(Activity activity,
        boolean allowLoginUI, Session.StatusCallback statusCallback) {
        OpenRequest openRequest = new OpenRequest(activity);
        openRequest.setPermissions(CommonAppUtils.FB_BASIC_PERMISSIONS);
        openRequest.setCallback(statusCallback);

        Session session = new Session.Builder(activity).build();

        if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState())
                || allowLoginUI) {
            Session.setActiveSession(session);
            session.openForRead(openRequest);

            return session;
        }

        return null;
    }

创建statuscallback实现

private class SessionStatusCallback implements Session.StatusCallback {
        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            // you can check session state and do whatever
        }
    }

注意添加创建

uiHelper = new UiLifecycleHelper(this, statusCallback);
        uiHelper.onCreate(savedInstanceState);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}