Look at
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
// You have an active cached session
}
That is probably the best way to detect.
题
My application will allow user to log in using Email, Twitter or Facebook. I'm using Facebook Android SDK on its last version.
How can I check if a user is already logged in at the onCreate method so I can display the login options if the user is logged out or redirect to the main activity if he is logged in?
I'm currently using the following code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
// this method is not run
解决方案
Look at
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
// You have an active cached session
}
That is probably the best way to detect.
其他提示
Please check my library https://github.com/antonkrasov/AndroidSocialNetworks
It allows you easily implement login for Facebook, Twitter, LinkedIn and Google Plus.