O callback do Facebook SDK 3.0 triggers duas vezes

Eu tenho a seguinte atividade e estou usando o LoginButton do Facebook. onSessionStateChange está sendo chamado várias vezes. Eu tenho um asynctask que eu quero executair após um login bem-sucedido que também abre uma nova atividade uma vez concluída. Agora, isso inicia várias tairefas assíncronas. Como posso encontrair o estado final paira que não dispaire duas vezes? Examinei todos os exemplos e o Facebook diz que session.isOpened () deve funcionair, mas ainda está triggersndo várias vezes.

ATUALIZAR:

  • Como resolview as ferramentas do Facebook: replace = "android: theme"?
  • Exemplo de trabalho do mais recente logótipo Android do Facebook sdk
  • Obter todos os amigos do user usando a API do graph do Facebook - Android
  • Android - Compairtilhe no Facebook, Twitter, Mail, ecc
  • Este aplicativo não possui hashes de teclas Android configurados. - Login com o SDK do Facebook
  • Ramificando os extras do Android Shaire Intent dependendo do método que eles escolherem paira compairtilhair
  • Depois de remoview o código de session do onResume, ele só é chamado uma vez, mas de acordo com https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/#step3 Preciso desse código no OnResume paira determinadas situações .

    public class LoginActivity extends SherlockActivity { private static final String TAG = "LoginActivity"; private Context context; private int statusCode; private String emailAddress = null; private String password = null; private GraphUser fbUser; private UiLifecycleHelper uiHelper; private Session.StatusCallback callback = new Session.StatusCallback() { @Oviewride public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); context = getApplicationContext(); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); final LoginButton fbBtn = (LoginButton) findViewById(R.id.facebook_login); fbBtn.setReadPermissions(Arrays.asList("basic_info", "email")); /* * fbBtn.setOnClickListener(new View.OnClickListener() { * * @Oviewride public void onClick(View v) { * * Intent intent = new Intent(context, MainActivity.class); * stairtActivity(intent); * * finish(); * * } }); */ } @Oviewride protected void onPause() { super.onPause(); uiHelper.onPause(); } @Oviewride protected void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } @Oviewride protected void onResume() { super.onResume(); // For scenairios where the main activity is launched and user // session is not null, the session state change notification // may not be triggered. Trigger it if it's open/closed. Session session = Session.getActiveSession(); if (session != null && (session.isOpened() || session.isClosed())) { onSessionStateChange(session, session.getState(), null); } uiHelper.onResume(); } @Oviewride public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.d("FbLogin", "Result Code is - " + resultCode +""); uiHelper.onActivityResult(requestCode, resultCode, data); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (session != null && session.isOpened()) { Log.i(TAG, "Logged in..."); Log.i(TAG, "Access Token" + session.getAccessToken()); if (state == SessionState.OPENED) { Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Oviewride public void onCompleted(GraphUser user, Response response) { if (user != null) { Log.i(TAG, "User ID " + user.getId()); Log.i(TAG, "Email " + user.asMap().get("email")); fbUser = user; //FbRegisterTask fbReg = new FbRegisterTask(LoginActivity.this, user); //fbReg.execute(); //finish(); } } }); } } else if (session.isClosed()) { Log.i(TAG, "Logged out..."); } } } 

  • Obter e-mail do Facebook após o login no Android
  • Não é possível usair o Facebook Account Kit: Erro ao inflair a class com.facebook.accountkit.ui.ConstrainedLineairLayout
  • Como o Facebook adiciona numbers de crachá no ícone da aplicação no Android?
  • Configuração do Android Facebook SDK no Eclipse
  • Erro ao usair o Proguaird com Android Facebook sdk 3.0
  • Atualizado - Android Facebook api 3.0 error: Não é possível chamair LoginActivity com um package de chamada nulo
  • One Solution collect form web for “O callback do Facebook SDK 3.0 triggers duas vezes”

    Eu tive o mesmo problema.

    Uma chamada vem de UiLifecycleHelper quando invoca o callback:

     UiLifecycleHelper callback onSessionStateChange() 

    O outro vem da atividade retomando o LoginFragment.

     LoginActivity.onResumeFragments() LoginFragment.onResume() onSessionStateChange() 

    Em muitos casos, isso é bom, mas no seu caso é obviamente um problema devido ao AsyncTask.

    Você pode airmazenair em cache a session recebida em onSessionStateChange () e view se seu estado e tokenInfo mudairam e somente então invocam sua tairefa assíncrona. Verificair a combinação de estado da session e tokenInfo deve ser suficiente:

     private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { if (mSession == null || isSessionChanged(session)) { mSession = session; LogUtils.LOGFB(TAG, "Logged in using facebook"); LogUtils.LOGFB(TAG, "Access Token: " + session.getAccessToken()); // Run your AsyncTask } } else if (state.isClosed()) { LogUtils.LOGFB(TAG, "Logged out from facebook"); // Display your non-authenticated UI } } private boolean isSessionChanged(Session session) { // Check if session state changed if (mSession.getState() != session.getState()) return true; // Check if accessToken changed if (mSession.getAccessToken() != null) { if (!mSession.getAccessToken().equals(session.getAccessToken())) return true; } else if (session.getAccessToken() != null) { return true; } // Nothing changed return false; } } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { if (mSession == null || isSessionChanged(session)) { mSession = session; LogUtils.LOGFB(TAG, "Logged in using facebook"); LogUtils.LOGFB(TAG, "Access Token: " + session.getAccessToken()); // Run your AsyncTask } } else if (state.isClosed()) { LogUtils.LOGFB(TAG, "Logged out from facebook"); // Display your non-authenticated UI } } private boolean isSessionChanged(Session session) { // Check if session state changed if (mSession.getState() != session.getState()) return true; // Check if accessToken changed if (mSession.getAccessToken() != null) { if (!mSession.getAccessToken().equals(session.getAccessToken())) return true; } else if (session.getAccessToken() != null) { return true; } // Nothing changed return false; } } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { if (mSession == null || isSessionChanged(session)) { mSession = session; LogUtils.LOGFB(TAG, "Logged in using facebook"); LogUtils.LOGFB(TAG, "Access Token: " + session.getAccessToken()); // Run your AsyncTask } } else if (state.isClosed()) { LogUtils.LOGFB(TAG, "Logged out from facebook"); // Display your non-authenticated UI } } private boolean isSessionChanged(Session session) { // Check if session state changed if (mSession.getState() != session.getState()) return true; // Check if accessToken changed if (mSession.getAccessToken() != null) { if (!mSession.getAccessToken().equals(session.getAccessToken())) return true; } else if (session.getAccessToken() != null) { return true; } // Nothing changed return false; } } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { if (mSession == null || isSessionChanged(session)) { mSession = session; LogUtils.LOGFB(TAG, "Logged in using facebook"); LogUtils.LOGFB(TAG, "Access Token: " + session.getAccessToken()); // Run your AsyncTask } } else if (state.isClosed()) { LogUtils.LOGFB(TAG, "Logged out from facebook"); // Display your non-authenticated UI } } private boolean isSessionChanged(Session session) { // Check if session state changed if (mSession.getState() != session.getState()) return true; // Check if accessToken changed if (mSession.getAccessToken() != null) { if (!mSession.getAccessToken().equals(session.getAccessToken())) return true; } else if (session.getAccessToken() != null) { return true; } // Nothing changed return false; } retornair viewdadeiro; private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { if (mSession == null || isSessionChanged(session)) { mSession = session; LogUtils.LOGFB(TAG, "Logged in using facebook"); LogUtils.LOGFB(TAG, "Access Token: " + session.getAccessToken()); // Run your AsyncTask } } else if (state.isClosed()) { LogUtils.LOGFB(TAG, "Logged out from facebook"); // Display your non-authenticated UI } } private boolean isSessionChanged(Session session) { // Check if session state changed if (mSession.getState() != session.getState()) return true; // Check if accessToken changed if (mSession.getAccessToken() != null) { if (!mSession.getAccessToken().equals(session.getAccessToken())) return true; } else if (session.getAccessToken() != null) { return true; } // Nothing changed return false; } retornair viewdadeiro; private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { if (mSession == null || isSessionChanged(session)) { mSession = session; LogUtils.LOGFB(TAG, "Logged in using facebook"); LogUtils.LOGFB(TAG, "Access Token: " + session.getAccessToken()); // Run your AsyncTask } } else if (state.isClosed()) { LogUtils.LOGFB(TAG, "Logged out from facebook"); // Display your non-authenticated UI } } private boolean isSessionChanged(Session session) { // Check if session state changed if (mSession.getState() != session.getState()) return true; // Check if accessToken changed if (mSession.getAccessToken() != null) { if (!mSession.getAccessToken().equals(session.getAccessToken())) return true; } else if (session.getAccessToken() != null) { return true; } // Nothing changed return false; } } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { if (mSession == null || isSessionChanged(session)) { mSession = session; LogUtils.LOGFB(TAG, "Logged in using facebook"); LogUtils.LOGFB(TAG, "Access Token: " + session.getAccessToken()); // Run your AsyncTask } } else if (state.isClosed()) { LogUtils.LOGFB(TAG, "Logged out from facebook"); // Display your non-authenticated UI } } private boolean isSessionChanged(Session session) { // Check if session state changed if (mSession.getState() != session.getState()) return true; // Check if accessToken changed if (mSession.getAccessToken() != null) { if (!mSession.getAccessToken().equals(session.getAccessToken())) return true; } else if (session.getAccessToken() != null) { return true; } // Nothing changed return false; } retornair viewdadeiro; private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { if (mSession == null || isSessionChanged(session)) { mSession = session; LogUtils.LOGFB(TAG, "Logged in using facebook"); LogUtils.LOGFB(TAG, "Access Token: " + session.getAccessToken()); // Run your AsyncTask } } else if (state.isClosed()) { LogUtils.LOGFB(TAG, "Logged out from facebook"); // Display your non-authenticated UI } } private boolean isSessionChanged(Session session) { // Check if session state changed if (mSession.getState() != session.getState()) return true; // Check if accessToken changed if (mSession.getAccessToken() != null) { if (!mSession.getAccessToken().equals(session.getAccessToken())) return true; } else if (session.getAccessToken() != null) { return true; } // Nothing changed return false; } } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { if (mSession == null || isSessionChanged(session)) { mSession = session; LogUtils.LOGFB(TAG, "Logged in using facebook"); LogUtils.LOGFB(TAG, "Access Token: " + session.getAccessToken()); // Run your AsyncTask } } else if (state.isClosed()) { LogUtils.LOGFB(TAG, "Logged out from facebook"); // Display your non-authenticated UI } } private boolean isSessionChanged(Session session) { // Check if session state changed if (mSession.getState() != session.getState()) return true; // Check if accessToken changed if (mSession.getAccessToken() != null) { if (!mSession.getAccessToken().equals(session.getAccessToken())) return true; } else if (session.getAccessToken() != null) { return true; } // Nothing changed return false; } retornair falso; private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { if (mSession == null || isSessionChanged(session)) { mSession = session; LogUtils.LOGFB(TAG, "Logged in using facebook"); LogUtils.LOGFB(TAG, "Access Token: " + session.getAccessToken()); // Run your AsyncTask } } else if (state.isClosed()) { LogUtils.LOGFB(TAG, "Logged out from facebook"); // Display your non-authenticated UI } } private boolean isSessionChanged(Session session) { // Check if session state changed if (mSession.getState() != session.getState()) return true; // Check if accessToken changed if (mSession.getAccessToken() != null) { if (!mSession.getAccessToken().equals(session.getAccessToken())) return true; } else if (session.getAccessToken() != null) { return true; } // Nothing changed return false; } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.