Я пытаюсь интегрировать Facebook в свое приложение для Android. Используя кнопку входа в систему Facebook, я попытался войти в систему. Когда я впервые установил приложение, он отлично работает и успешно подключился. Когда я выйду из системы с помощью этой кнопки, а затем попробуйте снова войти в систему, он отобразит диалог разрешений, но состояние возврата SessionState
будет закрыто. Какие-либо предложения? Вот мой код
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();
}
}