I have added facebook login to my app.
First time I am able to login without any issue. But after login and then I logout. I am getting this error in the logcat.
E/LoginFragment: Cannot call LoginFragment with a null calling package. This can occur if the launchMode of the caller is singleInstance.
I searched google a bit. Some errors were resolved by setting launchmode to standard. I didn't specify any launchmode. But still I tried with
<activity
android:name=".activities.LoginActivity"
android:launchMode="standard"/>
But got no success.
Here is my procedure to login.
1 Added FB dependency compile 'com.facebook.android:facebook-android-sdk:[4,5)'
2 I initialize FB sdk in Application
Class's onCreate()
After super.onCreate()
. AppEventsLogger.activateApp(this);
3 In my login activity created CallbackManager
instance on the onCreate()
of activity.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_login);
}
4 I used a custom button to login. When I clicked on fb login button. I am using this code.
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
//My Stuff Here
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,first_name,last_name,link,picture.type(large)");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
//Cancel Stuff
}
@Override
public void onError(FacebookException exception) {
exception.printStackTrace();
//Error Stuff
}
}); LoginManager.getInstance().logInWithReadPermissions((AppCompatActivity)context,
Arrays.asList("public_profile, email"));
5 I registered for callbacks in onActivityResult()
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
6 And to logout I have used LoginManager.getInstance().logOut()
7 But I try to login again with my custom button, the debug pointer goes to the line LoginManager.getInstance().registerCallback()
but none of the methods (onSuccess(LoginResult loginResult)
, onError()
, onError(FacebookException exception)
) of the callback gets call. And I get a log saying E/LoginFragment: Cannot call LoginFragment with a null calling package. This can occur if the launchMode of the caller is singleInstance.
Change this
LoginManager.getInstance().logInWithReadPermissions((AppCompatActivity)context,
Arrays.asList("public_profile, email"));
to
LoginManager.getInstance().logInWithReadPermissions(LoginActivity.this,
Arrays.asList("public_profile, email"));