I solved this problem implementing methods for manager changes of Session.
I mean after the autentication you have to wait that the session is opened.
So I added UiLifecycleHelper object and the method that facebook suggests:
public class SelectionFragment extends Fragment {
private MainActivity activity;
private Context context;
private UiLifecycleHelper uiHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = (MainActivity) getActivity();
context = activity.getApplicationContext();
uiHelper = new UiLifecycleHelper(activity, sessionCallback);
uiHelper.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.selection_fragment, container, false);
return view;
}
// Define a private variable that contains the implementation of the Session.StatusCallback listener:
private Session.StatusCallback sessionCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
@SuppressWarnings("deprecation")
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (session != null && session.isOpened()) {
makeMeRequest(session); // my request
} else {
...
}
}
@Override
public void onResume() {
super.onResume();
// For scenarios 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();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data, nativeDialogCallback);
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
activity = null;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
}