关闭活动时onActivityResult不会触发

时间:2014-04-07 01:41:50

标签: android facebook-sdk-3.1

当Facebook完成在ActivityB中返回我的用户数据时,我试图在ActivityA中触发onActivityResults,但我没有运气。有没有人有任何见解?通过内部类关闭活动是否有任何限制?

public class ActivityB extends Activity {

        private static final String URL_PREFIX_FRIENDS = "https://graph.facebook.com/me/friends?access_token=";
        private Session.StatusCallback statusCallback  = new SessionStatusCallback();;// = new SessionStatusCallback();

        public class SessionStatusCallback implements Session.StatusCallback {

            //NewPermissionsRequest newPermissionsRequest = new NewPermissionsRequest(this, Arrays.asList("email"));

            @Override
            public void call(Session session, SessionState state, Exception exception) {

                session = Session.getActiveSession();

                if (session.isOpened()) //if (session.isOpened() && !isFetching)
                {


                    Request getMe = Request.newMeRequest(session, new GraphUserCallback()
                    {
                        @Override
                            public void onCompleted(GraphUser user, Response response)
                        {
                            if (user != null)
                            {

                                org.json.JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
                                String jsonData = graphResponse.toString();
                                String email = graphResponse.optString("email");
                                String id = graphResponse.optString("id");
                                String facebookName = graphResponse.optString("name");
                                Intent intent = new Intent();
                                setResult(RESULT_OK, intent);
                                finish();
                            }
                        }
                    });
                    getMe.executeAsync();
                }
            }   
        }


        @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



            List<String> permission=new ArrayList<String>();
            permission.add("email");

            Session session = new Session.Builder(this.getApplicationContext()).setApplicationId("40423423767677").build();
            Session.setActiveSession(session);

            if (!session.isOpened() && !session.isClosed()) {
                session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback).setPermissions(permission));
            } else {
                Session.openActiveSession(this, true, statusCallback);
            }

        }

       @Override
       public void onActivityResult(int requestCode, int resultCode, Intent data) {
           super.onActivityResult(requestCode, resultCode, data);
           Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
       }
}

0 个答案:

没有答案