I am struggling to find a clear way, how to determine, if user is logged in with Facebook on my android application.
Official Facebook documentation says that:
You can see if a person is already logged in by checking AccessToken.getCurrentAccessToken() and Profile.getCurrentProfile().
However, AccessToken.getCurrentAccessToken()
will be available only if SDK initialization was completed. So as far as I understand, such approach might not work all the time:
FacebookSdk.sdkInitialize(this.getApplicationContext());
if (AccessToken.getCurrentAccessToken() != null) {
//good
}
Because, as it was discussed in this question:
How can i find my current login status - facebook API android
It says, that AccessTokenTracker()
callback onCurrentAccessTokenChanged()
might be fired async and therefore, it is possible to get null
value of getCurrentAccessToken()
in this case above (I would simply loose the race).
So if there is a chance of having null
value of getCurrentAccessToken
right after SDK init, and if, as far as I know, onCurrentAccessTokenChanged()
is NEVER executed if user is not logged in at all, so... how to check that properly? This seems like a deadlock to me. Am I missing here something?
What I have done: I have looked at official FB manual, implemented login in general, but this issue is giving me headaches. Also check some other SO questions, but all solutions do not explain what I want.
Moreover, I want to check this on application startup, so I do not have such things like onResume
, onStart
etc.