简体   繁体   中英

Android facebook login taking too much time

I'm using Facebook native log in authentication in my app. When user press log in button, after log in I want to move to next Activity . But after log in the button changed to log out and stay there for some time and then go to next activity after about 20 seconds.

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_main, container, false);

    LoginButton authButton = (LoginButton) view
            .findViewById(R.id.authButton);
    authButton.setFragment(this);
    authButton.setReadPermissions(Arrays.asList("email")); // permissions
    internalStorageManipulator = new InternalStorageManipulator(
            getActivity());

    return view;
}

private Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state,
            Exception exception) {
        if(!IsStateOpened)
        onSessionStateChange(session, state, exception);
    }
};

private void onSessionStateChange(Session session, SessionState state,
        Exception exception) {
    if (state.isOpened()) {
        Request.executeMeRequestAsync(session,
                new Request.GraphUserCallback() {

                    // callback after Graph API response with user
                    // object
                    @Override
                    public void onCompleted(GraphUser user,
                            Response response) {
                        if (user != null && !IsStateOpened) {
                            try {
                                internalStorageManipulator
                                        .setLoginState(true);
                                Dashboard dashboard = new Dashboard(getActivity());
                                internalStorageManipulator.setUserID(user.getId());
                                internalStorageManipulator.setLoginState(true);
                                internalStorageManipulator.setGCMID("");
//                                  getAsyncProfilePicture();

                                dashboard.LoginUser(user.getId(), user.asMap().get("email").toString(),user.getUsername(), "",
                                        (IHttpRequestCallBack) c);

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                });
    } else if (state.isClosed()) {
        Log.i(LOGIN_TAG, "Logged out...");
    }
}

@Override
public void onResume() {
    super.onResume();

    Session session = Session.getActiveSession();
    if (!internalStorageManipulator.getLoginState())
        if (session != null && (session.isOpened() || session.isClosed())) {
            onSessionStateChange(session, session.getState(), null);
        }
    uiHelper.onResume();
}

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

To avoid this use onpause() ,onResume() and onActivityResult()methods of your activity. create a dialog in create() method. hide and show in these methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM