Question Facebook 3.0 Android deuxième tentative de connexion retourne "État de session fermé"


J'essaie d'intégrer Facebook à mon application Android. En utilisant le bouton de connexion Facebook, j'ai essayé de me connecter. Lorsque j'installe la première application, elle fonctionne correctement et se connecte avec succès. Lorsque je me suis déconnecté en utilisant ce bouton, puis que j'essaie de me connecter à nouveau, le SessionState l'état de retour est fermé. Aucune suggestion? Voici mon code

    public class LoginActivity extends FragmentActivity{

    //  private Login login;
        private boolean isResumed = false;
        private BirthDayComp app;
        private int Login=0;
        private int LogOut=1;
    private int Count=LogOut+1;
    private boolean loged= false;
    private Fragment[] fragments = new Fragment[Count];
     private UiLifecycleHelper uiHelper;
        private Session.StatusCallback callback = new Session.StatusCallback() {
            @Override
            public void call(Session session, SessionState state, Exception exception) {
                onSessionStateChange(session, state, exception);
            }
        };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.login_fragment);
        uiHelper = new UiLifecycleHelper(this, callback);
            uiHelper.onCreate(savedInstanceState);

            FragmentManager fm = getSupportFragmentManager();
            fragments[Login]=fm.findFragmentById(R.id.loginfb);
            fragments[LogOut]=fm.findFragmentById(R.id.logoutfb);
            FragmentTransaction transaction = fm.beginTransaction();
            transaction.commit();
        /*if (savedInstanceState == null) {
            login = new Login();
            getSupportFragmentManager()
            .beginTransaction()
            .add(android.R.id.content, login)
            .commit();
        } else {
            login = (Login) getSupportFragmentManager()
                    .findFragmentById(android.R.id.content);
        }*/
    }


     @Override
        public void onResume() {
            super.onResume();
            uiHelper.onResume();
            isResumed = true;
        }

        @Override
        public void onPause() {
            super.onPause();
            uiHelper.onPause();
           /* Session session = Session.getActiveSession();
            session.removeCallback(callback);*/
            isResumed = false;
        }

        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
           // uiHelper.onActivityResult(requestCode, resultCode, data);
          //  super.onActivityResult(requestCode, resultCode, data);
            Session session = Session.getActiveSession();
            int sanitizedRequestCode = requestCode % 0x10000;
            session.onActivityResult(this, sanitizedRequestCode, resultCode, data);
        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            uiHelper.onDestroy();
        }

        @Override
        protected void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            uiHelper.onSaveInstanceState(outState);
        }

        @Override
        protected void onResumeFragments() {
            super.onResumeFragments();
            Session session = Session.getActiveSession();

            if (session != null && session.isOpened()) {
                // if the session is already open, try to show the selection fragment
                /*if(app.getFb()!=true){
                    app.setFb(true);
                }*/

                showFragment(Login, false);
            } else {
                // otherwise present the splash screen and ask the user to login.
                //app.setFb(false);
                showFragment(Login, false);
            }
        }

        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.
                session=Session.getActiveSession();

                state= session.getState();
                if (state.equals(SessionState.OPENED)) {
                    this.loged=true;
                    showFragment(Login, false);

                } else if (state.isClosed()) {
                    this.loged=false;
                    System.gc();
                    //session.closeAndClearTokenInformation();
                   // showFragment(Login, false);
                }
            }
        }

        private void showFragment(int fragmentIndex, boolean addToBackStack) {

            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction transaction = fm.beginTransaction();
            for (int i = 0; i < fragments.length; i++) {
                if (i == fragmentIndex) {
                    transaction.show(fragments[i]);
                } else {
                    transaction.hide(fragments[i]);
                }
            }
            if (addToBackStack) {
                transaction.addToBackStack(null);
            }
            transaction.commit();
        }




}

20
2018-06-06 11:58


origine


Réponses:


Ca va pour moi avec les états. J'ai des états ouverts et fermés selon les besoins.


0
2018-03-14 09:38