Android:Facebook LoginButton

时间:2013-07-03 12:29:27

标签: android facebook facebook-login

我有以下代码,

其中loginButton是Facebook LoginButton。

    loginButton.setReadPermissions(Arrays.asList("user_events"));
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
                @Override
                public void onUserInfoFetched(GraphUser user) {
                    MainActivity.this.user = user;
                    //pb.setVisibility(View.VISIBLE);
                    myApp.user = user;
                    eventi.clear();
                    myApp.eventiCompleti.clear();

                    if (user != null) {
                        String srt = "";
                        getEvents chn = new getEvents();

                    //OTHRE STUFF
                    foo...foo

现在问题如下。

我需要在按下Facebook LoginButton时拦截来执行其他操作

如果我设置

  loginButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // DO SOME OTHER STUFF
        }
    });

然后

 @Override
 public void onUserInfoFetched(GraphUser user)
不会调用

回调...

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我在会话生命周期的另一个时刻实现了请求的方法调用:

 private void onSessionStateChange(Session session, SessionState state,
        Exception exception) {
    if (isResumed) {
        FragmentManager manager = getSupportFragmentManager();
        int backStackSize = manager.getBackStackEntryCount();
        for (int i = 0; i < backStackSize; i++) {
            manager.popBackStack();
        }
        // check for the OPENED state instead of session.isOpened() since
        // for the
        // OPENED_TOKEN_UPDATED state, the selection fragment should already
        // be showing.
        if (state.equals(SessionState.OPENED)) {
            // showFragment(SELECTION, false);
            pb.setVisibility(View.VISIBLE);// <-- HERE IS THE METHOD I WANTED TO CALL
        } else if (state.isClosed()) {

        }
    }
}